Changeset 74


Ignore:
Timestamp:
12/16/11 21:41:43 (12 years ago)
Author:
Maciej Komosinski
Message:

improved documentation, compilation, and precision of numbers parsed

Location:
cpp/gdk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • cpp/gdk/extvalue.cpp

    r66 r74  
    279279                {
    280280                SString tmp;
    281                 sprintf(tmp.directAppend(20),"%g",ddata());
     281                sprintf(tmp.directAppend(20),"%.15g",ddata());
    282282                tmp.endAppend();
    283283                if ((!strchr(tmp,'.'))&&(!strchr(tmp,'e'))) tmp+=".0";
  • cpp/gdk/multiparamload.h

    r66 r74  
    1010#include "virtfile.h"
    1111
    12 /** "param" file parser for loading multiple objects.
     12/** This is the general "framsticks-format" file parser for loading multiple objects.
    1313    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).   
    1833 */
    1934class MultiParamLoader
     
    5065void load(const char* filename);
    5166
    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 */
    5371void addClass(ParamInterface *pi) {params+=pi;}
    5472void removeClass(ParamInterface *pi) {params-=pi;}
    5573void clearClasses() {params.clear();}
    5674
    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.
    6078 */
    6179virtual int go();
     
    6684VirtFILE *getFile() {return file;}
    6785
    68 /** abort immediately and close the file if needed */
     86/** Abort immediately and close the file if needed */
    6987void abort();
    7088/** @param conditions can be combined bitwise, eg. MultiParamLoader::BeforeObject |  MultiParamLoader::OnComment
     
    7492void noBreakOn(int conditions) {breakcond&=~conditions;}
    7593/**
    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
    79103@see getClass(), GetClassName()
    80104 */
     
    82106                       BeforeUnknown=4, OnComment=8, OnError=16, Loading=32 };
    83107
    84 /** can be used BeforeObject and AfterObject */
     108/** Can be used BeforeObject and AfterObject */
    85109ParamInterface *getClass() {return lastclass;}
    86 /** can be used BeforeUnknown, BeforeObject, AfterObject */
     110/** Can be used BeforeUnknown, BeforeObject, AfterObject */
    87111const SString& getClassName() {return lastunknown;}
    88 /** unknown object will be loaded if you set its class BeforeUnknown */
     112const void setClassName(SString n) {lastunknown=n;}
     113/** Unknown object will be loaded if you set its class BeforeUnknown */
    89114void setClass(ParamInterface *pi) {lastclass=pi;}
    90 /** can be used OnComment */
     115/** Can be used OnComment */
    91116const SString& getComment() {return lastcomment;}
    92 /** can be used OnError */
     117/** Can be used OnError */
    93118const SString& getError() {return lasterror;}
    94 /** can be used BeforeObject and BeforeUnknown */
     119/** Can be used BeforeObject and BeforeUnknown */
    95120int loadObjectNow(ParamInterface *pi);
    96 /** can be used BeforeObject */
     121/** Can be used BeforeObject */
    97122int 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. */
    100125int skipObject() {return loadObjectNow(&emptyparam);}
    101126/** @return 1 if no errors */
     
    109134
    110135#endif
     136
  • cpp/gdk/sstring.h

    r66 r74  
    137137int operator==(const SString &s) const {return equals(s);} ///< TRUE if equal
    138138const 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 array
     139char operator[](int i) const {return buf->txt[i];} ///< get char like in array
    140140
    141141/// return a substring of the current string
Note: See TracChangeset for help on using the changeset viewer.