Changeset 74
- Timestamp:
- 12/16/11 21:41:43 (13 years ago)
- Location:
- cpp/gdk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cpp/gdk/extvalue.cpp
r66 r74 279 279 { 280 280 SString tmp; 281 sprintf(tmp.directAppend(20),"% g",ddata());281 sprintf(tmp.directAppend(20),"%.15g",ddata()); 282 282 tmp.endAppend(); 283 283 if ((!strchr(tmp,'.'))&&(!strchr(tmp,'e'))) tmp+=".0"; -
cpp/gdk/multiparamload.h
r66 r74 10 10 #include "virtfile.h" 11 11 12 /** "param" file parser for loading multiple objects.12 /** This is the general "framsticks-format" file parser for loading multiple objects. 13 13 The loader can be configured to recognize multiple object types from object headers 14 and automatically call ParamInterface::load for matching class. 15 By using MultiParamLoader::go() function you can receive status events, they can be 16 used to handle multiple object instances or parse complex files (see loadtest.cpp sample code). 17 A simple MultiParamLoader::run() can be used if you need any events. 14 and automatically call ParamInterface::load for the matching class. 15 16 Your code should repeatedly call MultiParamLoader::go() method and check the status after each call, until the end of file. 17 The loader pauses before and/or after each object giving you a chance to perform your application-specific actions (see MultiParamLoader::breakOn()). 18 If your application does not require any special actions, then the simple MultiParamLoader:run() can be used. 19 The word "record" (and "record type") used in this description refer to the textual form of a serialized object - this is to avoid confusion with 'live' objects passed to the loader methods. "Record type" can be the same as the class name, but it does not have to be the same. For example, the most common record type for storing the Genotype object is called "org" (think: organism) instead of "Genotype". 20 21 Typical usage scenarios: 22 1. Loading a file that contains at most one object of any given class: 23 - declare the object class(es) - MultiParamLoader::addClass() 24 - call MultiParamLoader::run() 25 - and that's all, the records from the file will be loaded into the corresponding objects 26 27 2. Loading multiple objects and adding them to a list (see loadtest.cpp for a sample code that demonstrates this scenario) 28 - declare the object class giving the empty "template" object - MultiParamLoader::addClass() 29 - set breakOn(AfterObject) 30 - call MultiParamLoader::go() in a loop 31 - the returned status will be equal to AfterObject each time an object is loaded. One can detect this condition and create the real object from our template object 32 (alternatively, one could breakOn(BeforeObject) and use MultiParamLoader::loadObjectNow(ParamInterface*) to load the incoming object into a newly created object). 18 33 */ 19 34 class MultiParamLoader … … 50 65 void load(const char* filename); 51 66 52 /** register the object class. classes' names will be matched with object headers ("xxx:" in the file) */ 67 /** Register the object class. Class names will be matched with object headers ("xxx:" in the input file). 68 Used with breakOn(BeforeObject) and/or breakOn(AfterObject). 69 Note that registered classes will only work when the record name matches the class name, otherwise breakOn(BeforeUnknown) must be used and then getClassName() to check for the expected record. 70 */ 53 71 void addClass(ParamInterface *pi) {params+=pi;} 54 72 void removeClass(ParamInterface *pi) {params-=pi;} 55 73 void clearClasses() {params.clear();} 56 74 57 /** to be used in the main loop: while(event=loader.go()) { ... }58 loader.go() will return on specified events (@see breakOn(), noBreakOn()) 59 then you can handle the event and resume loading 75 /** To be used in the main loop: while(event=loader.go()) { ... } 76 loader.go() will return on specified events (@see breakOn(), noBreakOn()), 77 then you can handle the event and resume loading. 60 78 */ 61 79 virtual int go(); … … 66 84 VirtFILE *getFile() {return file;} 67 85 68 /** abort immediately and close the file if needed */86 /** Abort immediately and close the file if needed */ 69 87 void abort(); 70 88 /** @param conditions can be combined bitwise, eg. MultiParamLoader::BeforeObject | MultiParamLoader::OnComment … … 74 92 void noBreakOn(int conditions) {breakcond&=~conditions;} 75 93 /** 76 - BeforeObject: found an object with recognized classname 77 - AfterObject: the object was loaded into the registered class interface 78 - BeforeUnknown: unknown (not registered) object header detected. 94 These constants are used as arguments in breakOn(), and as status values from go() and getStatus(). 95 The user code can define some classes for automatic recognition (using addClass()); such records can be read without performing any additional actions. 96 97 - BeforeObject: found an object with recognized classname (addClass()). Application code can choose to skip the incoming record (skipObject()), redirect the incoming data into a different object (loadObjectNow(ParamInterface*)), or do nothing for default behavior (loading into previously registered object). 98 99 - AfterObject: the object was loaded into the registered class interface (addClass()). This is to allow for additional actions after loading the object (e.g. data validation). 100 101 - BeforeUnknown: unknown (not registered) object header detected. Like in BeforeObject, the application can skipObject() or loadObjectNow(). 102 79 103 @see getClass(), GetClassName() 80 104 */ … … 82 106 BeforeUnknown=4, OnComment=8, OnError=16, Loading=32 }; 83 107 84 /** can be used BeforeObject and AfterObject */108 /** Can be used BeforeObject and AfterObject */ 85 109 ParamInterface *getClass() {return lastclass;} 86 /** can be used BeforeUnknown, BeforeObject, AfterObject */110 /** Can be used BeforeUnknown, BeforeObject, AfterObject */ 87 111 const SString& getClassName() {return lastunknown;} 88 /** unknown object will be loaded if you set its class BeforeUnknown */ 112 const void setClassName(SString n) {lastunknown=n;} 113 /** Unknown object will be loaded if you set its class BeforeUnknown */ 89 114 void setClass(ParamInterface *pi) {lastclass=pi;} 90 /** can be used OnComment */115 /** Can be used OnComment */ 91 116 const SString& getComment() {return lastcomment;} 92 /** can be used OnError */117 /** Can be used OnError */ 93 118 const SString& getError() {return lasterror;} 94 /** can be used BeforeObject and BeforeUnknown */119 /** Can be used BeforeObject and BeforeUnknown */ 95 120 int loadObjectNow(ParamInterface *pi); 96 /** can be used BeforeObject */121 /** Can be used BeforeObject */ 97 122 int loadObjectNow() {return loadObjectNow(getClass());} 98 /** can be used BeforeObject and BeforeUnknown.99 object data will not be loaded. */123 /** Can be used BeforeObject and BeforeUnknown. 124 Object data will not be loaded. */ 100 125 int skipObject() {return loadObjectNow(&emptyparam);} 101 126 /** @return 1 if no errors */ … … 109 134 110 135 #endif 136 -
cpp/gdk/sstring.h
r66 r74 137 137 int operator==(const SString &s) const {return equals(s);} ///< TRUE if equal 138 138 const char* operator()(int p) const {return buf->txt+p;} ///< pointer to p'th character in SString 139 char operator[](int i) {return buf->txt[i];} ///< get char like in array139 char operator[](int i) const {return buf->txt[i];} ///< get char like in array 140 140 141 141 /// return a substring of the current string
Note: See TracChangeset
for help on using the changeset viewer.