Changeset 157
- Timestamp:
- Jan 28, 2006 2:05:44 PM (18 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/cee/RpLibraryCInterface.h
r125 r157 15 15 #ifdef __cplusplus 16 16 extern "C" { 17 #endif 17 #endif 18 18 19 19 typedef struct RpLibrary RpLibrary; … … 21 21 // lib definition functions 22 22 // 23 RpLibrary* rpLibrary(const char* path);24 void rpFreeLibrary(RpLibrary** lib);23 RpLibrary* rpLibrary (const char* path); 24 int rpFreeLibrary (RpLibrary** lib); 25 25 26 26 // RpLibrary member functions 27 RpLibrary* rpElement(RpLibrary* lib, const char* path);28 RpLibrary* rpElementAsObject(RpLibrary* lib, const char* path);29 const char* rpElementAsType (RpLibrary* lib, const char* path);30 const char* rpElementAsComp (RpLibrary* lib, const char* path);31 const char* rpElementAsId (RpLibrary* lib, const char* path);27 RpLibrary* rpElement (RpLibrary* lib, const char* path); 28 RpLibrary* rpElementAsObject (RpLibrary* lib, const char* path); 29 int rpElementAsType (RpLibrary* lib, const char* path, const char** retCStr); 30 int rpElementAsComp (RpLibrary* lib, const char* path, const char** retCStr); 31 int rpElementAsId (RpLibrary* lib, const char* path, const char** retCStr); 32 32 33 RpLibrary* rpChildren (RpLibrary* lib, 34 const char* path, 35 RpLibrary* childEle); 36 RpLibrary* rpChildrenByType (RpLibrary* lib, 37 const char* path, 38 RpLibrary* childEle, 39 const char* type ); 33 RpLibrary* rpChildren (RpLibrary* lib, 34 const char* path, 35 RpLibrary* childEle ); 36 RpLibrary* rpChildrenByType (RpLibrary* lib, 37 const char* path, 38 RpLibrary* childEle, 39 const char* type ); 40 41 int rpGet (RpLibrary* lib, const char* path, const char** retCStr); 42 int rpGetString (RpLibrary* lib, const char* path, const char** retCStr); 43 int rpGetDouble (RpLibrary* lib, const char* path, double* retDVal); 44 45 int rpPut (RpLibrary* lib, 46 const char* path, 47 const char* value, 48 const char* id, 49 int append ); 40 50 /* 41 RpLibrary* rpChildrenAsObject (RpLibrary* lib, 42 const char* path, 43 const char* type ); 44 const char* rpChildrenAsType (RpLibrary* lib, 45 const char* path, 46 const char* type ); 47 const char* rpChildrenAsComp (RpLibrary* lib, 48 const char* path, 49 const char* type ); 50 const char* rpChildrenAsId (RpLibrary* lib, 51 const char* path, 52 const char* type ); 53 */ 51 int rpPutStringId (RpLibrary* lib, 52 const char* path, 53 const char* value, 54 const char* id, 55 int append ); 56 */ 57 int rpPutString (RpLibrary* lib, 58 const char* path, 59 const char* value, 60 int append ); 61 /* 62 int rpPutDoubleId (RpLibrary* lib, 63 const char* path, 64 double value, 65 const char* id, 66 int append ); 67 */ 68 int rpPutDouble (RpLibrary* lib, 69 const char* path, 70 double value, 71 int append ); 54 72 55 const char* rpGet (RpLibrary* lib, const char* path); 56 const char* rpGetString (RpLibrary* lib, const char* path); 57 double rpGetDouble (RpLibrary* lib, const char* path); 73 int rpXml (RpLibrary* lib, const char** retCStr); 58 74 59 void rpPut (RpLibrary* lib, 60 const char* path, 61 const char* value, 62 const char* id, 63 int append ); 64 void rpPutStringId (RpLibrary* lib, 65 const char* path, 66 const char* value, 67 const char* id, 68 int append ); 69 void rpPutString (RpLibrary* lib, 70 const char* path, 71 const char* value, 72 int append ); 73 void rpPutDoubleId (RpLibrary* lib, 74 const char* path, 75 double value, 76 const char* id, 77 int append ); 78 void rpPutDouble (RpLibrary* lib, 79 const char* path, 80 double value, 81 int append ); 75 int rpNodeComp (RpLibrary* node, const char** retCStr); 76 int rpNodeType (RpLibrary* node, const char** retCStr); 77 int rpNodeId (RpLibrary* node, const char** retCStr); 82 78 83 const char* rpXml (RpLibrary* lib); 84 85 const char* rpNodeComp (RpLibrary* node); 86 const char* rpNodeType (RpLibrary* node); 87 const char* rpNodeId (RpLibrary* node); 88 89 void rpResult (RpLibrary* lib); 79 int rpResult (RpLibrary* lib); 90 80 91 81 #ifdef __cplusplus -
trunk/src/cee/RpLibraryCInterface.cc
r125 r157 19 19 #endif 20 20 21 RpLibrary* 22 rpLibrary (const char* path) 23 { 24 return new RpLibrary(path); 25 } 26 27 void 28 rpFreeLibrary (RpLibrary** lib) 29 { 30 if (lib && (*lib)) { 31 delete (*lib); 32 (*lib) = NULL; 33 } 34 } 35 36 RpLibrary* 37 rpElement (RpLibrary* lib, const char* path) 38 { 39 return lib->element(path); 40 } 41 42 RpLibrary* 43 rpElementAsObject (RpLibrary* lib, const char* path) 44 { 45 return rpElement(lib,path); 46 } 47 48 const char* 49 rpElementAsType (RpLibrary* lib, const char* path) 50 { 51 static std::string retStr = ""; 52 RpLibrary* retLib = lib->element(path); 53 54 if (retLib) { 55 retStr = retLib->nodeType(); 56 } 57 58 return retStr.c_str(); 59 } 60 61 const char* 62 rpElementAsComp (RpLibrary* lib, const char* path) 63 { 64 static std::string retStr = ""; 65 RpLibrary* retLib = lib->element(path); 66 67 if (retLib) { 68 retStr = retLib->nodeComp(); 69 } 70 71 return retStr.c_str(); 72 } 73 74 const char* 75 rpElementAsId (RpLibrary* lib, const char* path) 76 { 77 static std::string retStr = ""; 78 RpLibrary* retLib = lib->element(path); 79 80 if (retLib) { 81 retStr = retLib->nodeId(); 82 } 83 84 return retStr.c_str(); 85 } 86 87 88 RpLibrary* 89 rpChildren (RpLibrary* lib, const char* path, RpLibrary* childEle ) 90 { 91 return lib->children(path,childEle); 92 } 93 94 RpLibrary* 95 rpChildrenByType( RpLibrary* lib, 96 const char* path, 97 RpLibrary* childEle, 98 const char* type ) 99 { 100 return lib->children(path,childEle,type); 101 } 102 103 const char* 104 rpGet (RpLibrary* lib, const char* path) 105 { 106 static std::string retStr = ""; 107 retStr = lib->getString(path); 108 return retStr.c_str(); 109 } 110 111 const char* 112 rpGetString (RpLibrary* lib, const char* path) 113 { 114 static std::string retStr = ""; 115 retStr = lib->getString(path); 116 return retStr.c_str(); 117 } 118 119 double 120 rpGetDouble (RpLibrary* lib, const char* path) 121 { 122 return lib->getDouble(path); 123 } 124 125 void 126 rpPut (RpLibrary* lib, 127 const char* path, 128 const char* value, 129 const char* id, 130 int append ) 131 { 132 lib->put(path,value,id,append); 133 } 134 135 void 136 rpPutStringId (RpLibrary* lib, 137 const char* path, 138 const char* value, 139 const char* id, 140 int append ) 141 { 142 lib->put(path,value,id,append); 143 } 144 145 void 146 rpPutString ( RpLibrary* lib, 21 RpLibrary* 22 rpLibrary (const char* path) 23 { 24 return (new RpLibrary(path)); 25 } 26 27 int 28 rpFreeLibrary (RpLibrary** lib) 29 { 30 int retVal = 1; 31 32 if (lib && (*lib)) { 33 delete (*lib); 34 (*lib) = NULL; 35 retVal = 0; 36 } 37 38 return retVal; 39 } 40 41 RpLibrary* 42 rpElement (RpLibrary* lib, const char* path) 43 { 44 return (lib->element(path)); 45 } 46 47 RpLibrary* 48 rpElementAsObject (RpLibrary* lib, const char* path) 49 { 50 return rpElement(lib,path); 51 } 52 53 54 int 55 rpElementAsType (RpLibrary* lib, const char* path, const char** retCStr) 56 { 57 int retVal = 1; 58 static std::string retStr = ""; 59 RpLibrary* retLib = lib->element(path); 60 61 if (retLib) { 62 retStr = retLib->nodeType(); 63 // check to see if retStr is empty 64 retVal = 0; 65 } 66 67 *retCStr = retStr.c_str(); 68 69 return retVal; 70 } 71 72 int 73 rpElementAsComp (RpLibrary* lib, const char* path, const char** retCStr) 74 { 75 int retVal = 1; 76 static std::string retStr = ""; 77 RpLibrary* retLib = lib->element(path); 78 79 if (retLib) { 80 retStr = retLib->nodeComp(); 81 // check to see if retStr is empty 82 retVal = 0; 83 } 84 85 *retCStr = retStr.c_str(); 86 return retVal; 87 } 88 89 int 90 rpElementAsId (RpLibrary* lib, const char* path, const char** retCStr) 91 { 92 int retVal = 1; 93 static std::string retStr = ""; 94 RpLibrary* retLib = lib->element(path); 95 96 if (retLib) { 97 retStr = retLib->nodeId(); 98 // check to see if retStr is empty 99 retVal = 0; 100 } 101 102 *retCStr = retStr.c_str(); 103 return retVal; 104 } 105 106 RpLibrary* 107 rpChildren (RpLibrary* lib, const char* path, RpLibrary* childEle ) 108 { 109 return ( lib->children(path,childEle) ); 110 } 111 112 RpLibrary* 113 rpChildrenByType( RpLibrary* lib, 147 114 const char* path, 148 const char* value, 149 int append ) 150 { 151 lib->put(path,value,"",append); 152 } 153 154 void 155 rpPutDoubleId (RpLibrary* lib, 156 const char* path, 157 double value, 158 const char* id, 159 int append ) 160 { 161 lib->put(path,value,id,append); 162 } 163 164 void 165 rpPutDouble (RpLibrary* lib, 166 const char* path, 167 double value, 168 int append ) 169 { 170 lib->put(path,value,"",append); 171 } 172 173 const char* 174 rpXml (RpLibrary* lib) 175 { 176 static std::string retStr = ""; 115 RpLibrary* childEle, 116 const char* type ) 117 { 118 return ( lib->children(path,childEle,type) ); 119 } 120 121 int 122 rpGet (RpLibrary* lib, const char* path, const char** retCStr) 123 { 124 return rpGetString(lib,path,retCStr); 125 } 126 127 int 128 rpGetString (RpLibrary* lib, const char* path, const char** retCStr) 129 { 130 int retVal = 0; 131 static std::string retStr = ""; 132 133 retStr = lib->getString(path); 134 135 *retCStr = retStr.c_str(); 136 return retVal; 137 } 138 139 int 140 rpGetDouble (RpLibrary* lib, const char* path, double* retDVal) 141 { 142 int retVal = 0; 143 *retDVal = lib->getDouble(path); 144 return retVal; 145 } 146 147 int 148 rpPut (RpLibrary* lib, 149 const char* path, 150 const char* value, 151 const char* id, 152 int append ) 153 { 154 int retVal = 0; 155 lib->put(path,value,id,append); 156 return retVal; 157 } 158 159 /* 160 int 161 rpPutStringId (RpLibrary* lib, 162 const char* path, 163 const char* value, 164 const char* id, 165 int append ) 166 { 167 int retVal = 0; 168 lib->put(path,value,id,append); 169 return retVal; 170 } 171 */ 172 173 int 174 rpPutString ( RpLibrary* lib, 175 const char* path, 176 const char* value, 177 int append ) 178 { 179 int retVal = 0; 180 lib->put(path,value,"",append); 181 return retVal; 182 } 183 184 /* 185 int 186 rpPutDoubleId (RpLibrary* lib, 187 const char* path, 188 double value, 189 const char* id, 190 int append ) 191 { 192 int retVal = 0; 193 lib->put(path,value,id,append); 194 return retVal; 195 } 196 */ 197 198 int 199 rpPutDouble (RpLibrary* lib, 200 const char* path, 201 double value, 202 int append ) 203 { 204 int retVal = 0; 205 lib->put(path,value,"",append); 206 return retVal; 207 } 208 209 int 210 rpXml (RpLibrary* lib, const char** retCStr) 211 { 212 int retVal = 1; 213 static std::string retStr = ""; 214 215 if (lib != NULL) { 216 retStr = ""; 177 217 retStr = lib->xml(); 178 return retStr.c_str(); 179 } 180 181 const char* 182 rpNodeComp (RpLibrary* node) 183 { 184 static std::string retStr = ""; 218 219 // string should never be empty after lib->xml fxn call 220 // lib->xml returns xml header at the very least. 221 if ( !retStr.empty() ) { 222 retVal = 0; 223 } 224 } 225 226 *retCStr = retStr.c_str(); 227 return retVal; 228 } 229 230 int 231 rpNodeComp (RpLibrary* node, const char** retCStr) 232 { 233 int retVal = 1; 234 static std::string retStr = ""; 235 236 if (node != NULL) { 237 retStr = ""; 185 238 retStr = node->nodeComp(); 186 return retStr.c_str(); 187 } 188 189 const char* 190 rpNodeType (RpLibrary* node) 191 { 192 static std::string retStr = ""; 239 if ( !retStr.empty() ) { 240 retVal = 0; 241 } 242 *retCStr = retStr.c_str(); 243 } 244 245 return retVal; 246 } 247 248 int 249 rpNodeType (RpLibrary* node, const char** retCStr) 250 { 251 int retVal = 1; 252 static std::string retStr = ""; 253 254 if (node != NULL) { 255 retStr = ""; 193 256 retStr = node->nodeType(); 194 return retStr.c_str(); 195 } 196 197 const char* 198 rpNodeId (RpLibrary* node) 199 { 200 static std::string retStr = ""; 257 if ( !retStr.empty() ) { 258 retVal = 0; 259 } 260 *retCStr = retStr.c_str(); 261 } 262 263 return retVal; 264 } 265 266 int 267 rpNodeId (RpLibrary* node, const char** retCStr) 268 { 269 int retVal = 0; 270 static std::string retStr = ""; 271 272 if (node != NULL) { 273 retStr = ""; 201 274 retStr = node->nodeId(); 202 return retStr.c_str(); 203 } 204 205 void 206 rpResult (RpLibrary* lib) 207 { 208 // signal the processing is complete 209 lib->result(); 210 } 275 if ( !retStr.empty() ) { 276 retVal = 0; 277 } 278 *retCStr = retStr.c_str(); 279 } 280 281 return retVal; 282 } 283 284 int 285 rpResult (RpLibrary* lib) 286 { 287 int retVal = 0; 288 // signal the processing is complete 289 lib->result(); 290 return retVal; 291 } 211 292 212 293 #ifdef __cplusplus -
trunk/test/src/RpLibraryC_test.c
r142 r157 10 10 #include "RpLibraryCInterface.h" 11 11 12 12 int test_lib(RpLibrary** lib, const char* path); 13 13 int test_element (RpLibrary* lib, const char* path ); 14 14 int test_get (RpLibrary* lib, const char* path ); … … 26 26 int test_childrenByType (RpLibrary* lib, const char* path, const char* type ); 27 27 28 int test_lib (RpLibrary** lib, const char* path) { 29 30 int retVal = 0; 31 32 *lib = NULL; 33 *lib = rpLibrary(path); 34 35 printf("TESTING LIBRARY: path = %s\n", path); 36 37 if (*lib != NULL) { 38 printf("creation of library successful\n"); 39 } 40 else { 41 printf("creation of library failed\n"); 42 retVal += 1; 43 } 44 45 printf ("lib = %x\n",(unsigned int)(*lib)); 46 47 return retVal; 48 } 49 28 50 int test_element (RpLibrary* lib, const char* path ) 29 51 { 30 int retVal = 1;52 int retVal = 0; 31 53 RpLibrary* searchEle = NULL; 32 54 const char* type = NULL; … … 37 59 38 60 searchEle = rpElement(lib,path); 39 type = rpElementAsType(lib,path);40 comp = rpElementAsComp(lib,path);41 id = rpElementAsId(lib,path);61 retVal += rpElementAsType(lib,path,&type); 62 retVal += rpElementAsComp(lib,path,&comp); 63 retVal += rpElementAsId(lib,path,&id); 42 64 43 65 if (!searchEle) { 44 66 printf("searchEle is NULL\n"); 45 retVal = 1;67 retVal += 1; 46 68 } 47 69 else { … … 50 72 printf("searchEle type = :%s:\n", type); 51 73 52 comp = rpNodeComp(searchEle);53 id = rpNodeId(searchEle);54 type = rpNodeType(searchEle);74 retVal += rpNodeComp(searchEle,&comp); 75 retVal += rpNodeId(searchEle,&id); 76 retVal += rpNodeType(searchEle,&type); 55 77 56 78 printf("searchEle comp = :%s:\n", comp); … … 58 80 printf("searchEle type = :%s:\n", type); 59 81 60 retVal = 0;61 82 } 62 83 … … 66 87 int test_getString (RpLibrary* lib, const char* path ) 67 88 { 68 int retVal = 1;89 int retVal = 0; 69 90 const char* searchVal = NULL; 70 91 71 92 printf("TESTING GET String: path = %s\n", path); 72 93 73 searchVal = rpGetString(lib,path);74 75 if ( !searchVal || *searchVal == '\0') {94 retVal += rpGetString(lib,path,&searchVal); 95 96 if ( (retVal) || !searchVal || *searchVal == '\0') { 76 97 printf("searchVal is EMPTY STRING\n"); 77 retVal = 1;98 retVal += 1; 78 99 } 79 100 else { … … 87 108 int test_getDouble (RpLibrary* lib, const char* path ) 88 109 { 89 int retVal = 1;110 int retVal = 0; 90 111 double searchVal = 0.0; 91 112 92 113 printf("TESTING GET Double: path = %s\n", path); 93 114 94 searchVal = rpGetDouble(lib,path); 95 96 printf("searchVal = :%f:\n", searchVal); 97 retVal = 0; 115 retVal = rpGetDouble(lib,path,&searchVal); 116 117 if (!retVal) { 118 printf("searchVal = :%f:\n", searchVal); 119 } 120 else { 121 printf("GET Double: FAILED\n"); 122 } 98 123 99 124 return retVal; … … 102 127 int test_children (RpLibrary* lib, const char* path) 103 128 { 104 int retVal = 1;129 int retVal = 0; 105 130 RpLibrary* childEle = NULL; 106 131 const char* id = NULL; … … 111 136 112 137 while ( (childEle = rpChildren(lib,path,childEle)) ) { 113 comp = rpNodeComp(childEle);114 id = rpNodeId(childEle);115 type = rpNodeType(childEle);138 retVal += rpNodeComp(childEle,&comp); 139 retVal += rpNodeId(childEle,&id); 140 retVal += rpNodeType(childEle,&type); 116 141 117 142 printf("childEle comp = :%s:\n",comp); 118 143 printf("childEle id = :%s:\n",id); 119 144 printf("childEle type = :%s:\n",type); 120 121 } 122 123 retVal = 0; 145 } 124 146 125 147 return retVal; … … 128 150 int test_childrenByType (RpLibrary* lib, const char* path, const char* searchType ) 129 151 { 130 int retVal = 1;152 int retVal = 0; 131 153 RpLibrary* childEle = NULL; 132 154 const char* id = NULL; … … 137 159 138 160 while ( (childEle = rpChildrenByType(lib,path,childEle,searchType)) ) { 139 comp = rpNodeComp(childEle);140 id = rpNodeId(childEle);141 type = rpNodeType(childEle);161 retVal += rpNodeComp(childEle,&comp); 162 retVal += rpNodeId(childEle,&id); 163 retVal += rpNodeType(childEle,&type); 142 164 143 165 printf("childEle comp = :%s:\n",comp); 144 166 printf("childEle id = :%s:\n",id); 145 167 printf("childEle type = :%s:\n",type); 146 147 } 148 149 retVal = 0; 168 } 150 169 151 170 return retVal; … … 154 173 int test_putString (RpLibrary* lib, const char* path, const char* value, int append) 155 174 { 156 int retVal = 1;175 int retVal = 0; 157 176 const char* searchVal = NULL; 158 177 159 178 printf("TESTING PUT String: path = %s\n", path); 160 179 161 rpPutString(lib,path,value,append); 162 searchVal = rpGetString(lib, path); 163 164 if (!searchVal || *searchVal == '\0') { 165 printf("searchVal is EMPTY STRING\n"); 166 retVal = 1; 180 retVal += rpPutString(lib,path,value,append); 181 if (!retVal) { 182 retVal += rpGetString(lib, path, &searchVal); 183 } 184 185 if (retVal || !searchVal || *searchVal == '\0') { 186 printf("searchVal is EMPTY STRING, or there was an error\n"); 167 187 } 168 188 else { 169 189 printf("searchVal = :%s:\n", searchVal); 170 retVal = 0;171 190 } 172 191 … … 176 195 int test_putDouble (RpLibrary* lib, const char* path, double value, int append) 177 196 { 178 int retVal = 1;197 int retVal = 0; 179 198 double searchVal = 0.0; 180 199 181 200 printf("TESTING PUT String: path = %s\n", path); 182 201 183 rpPutDouble(lib,path,value,append); 184 searchVal = rpGetDouble(lib, path); 185 printf("searchVal = :%f:\n", searchVal); 186 retVal = 0; 202 retVal += rpPutDouble(lib,path,value,append); 203 if (!retVal) { 204 retVal += rpGetDouble(lib, path,&searchVal); 205 } 206 207 if ( retVal ){ 208 printf("ERROR while retrieving searchVal\n"); 209 } 210 else { 211 printf("searchVal = :%f:\n", searchVal); 212 } 187 213 188 214 return retVal; … … 193 219 { 194 220 RpLibrary* lib = NULL; 221 int err = 0; 222 const char* retStr = NULL; 195 223 196 224 if (argc < 2) … … 200 228 } 201 229 202 lib = rpLibrary(argv[1]);230 test_lib(&lib,argv[1]); 203 231 204 232 test_element(lib,"input.number(min)"); … … 225 253 test_childrenByType(lib,"input.number(test)","preset"); 226 254 227 printf("XML = \n%s\n",rpXml(lib)); 255 err = rpXml(lib,&retStr); 256 257 if ( !err ) { 258 printf("XML = \n%s\n",retStr); 259 } 260 else { 261 printf("rpXML failed\n"); 262 } 228 263 229 264 rpFreeLibrary(&lib);
Note: See TracChangeset
for help on using the changeset viewer.