Changeset 720 for cpp/frams/param


Ignore:
Timestamp:
01/14/18 11:24:22 (6 years ago)
Author:
Maciej Komosinski
Message:

Param::save2() renamed to saveSingleLine(); unified Param::load() so that it gets a single-line/multi-line format selector

Location:
cpp/frams/param
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/param/multiparamload.cpp

    r535 r720  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2015  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2018  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    1010void MultiParamLoader::init()
    1111{
    12 file=0; ownfile=0;
    13 status=0;
    14 reset();
     12        file = 0; ownfile = 0;
     13        status = 0;
     14        reset();
    1515}
    1616
    1717void MultiParamLoader::reset()
    1818{
    19 status=0;
    20 breakcond=OnError;
    21 aborting=false;
    22 emptyparam.setParamTab(empty_paramtab);
    23 linenum=0;
     19        status = 0;
     20        breakcond = OnError;
     21        aborting = false;
     22        emptyparam.setParamTab(empty_paramtab);
     23        linenum = 0;
    2424}
    2525
    2626int MultiParamLoader::findObject(const ExtObject &o)
    2727{
    28 for(int i=0;i<objects.size();i++)
    29         if ((*objects(i))==o)
    30                 return i;
    31 return -1;
     28        for (int i = 0; i < objects.size(); i++)
     29                if ((*objects(i)) == o)
     30                        return i;
     31        return -1;
    3232}
    3333
    3434void MultiParamLoader::removeObject(const ExtObject &o)
    3535{
    36 int i=findObject(o);
    37 if (i>=0)
    38         {
    39         delete objects(i);
    40         objects-=i;
     36        int i = findObject(o);
     37        if (i >= 0)
     38        {
     39                delete objects(i);
     40                objects -= i;
    4141        }
    4242}
     
    4444void MultiParamLoader::clearObjects()
    4545{
    46 FOREACH(ExtObject*,o,objects)
    47         delete o;
    48 objects.clear();
     46        FOREACH(ExtObject*, o, objects)
     47                delete o;
     48        objects.clear();
    4949}
    5050
    5151void MultiParamLoader::load()
    5252{
    53 clearstack();
    54 if (!file)
    55         {
    56         lasterror="can't open file";
    57         status=OnError;
    58         return;
    59         }
    60 status=Loading;
    61 aborting=false;
     53        clearstack();
     54        if (!file)
     55        {
     56                lasterror = "can't open file";
     57                status = OnError;
     58                return;
     59        }
     60        status = Loading;
     61        aborting = false;
    6262}
    6363
    6464void MultiParamLoader::abort()
    6565{
    66 if (file && ownfile)
    67         {
    68         delete file;
    69         file=0;
    70         }
    71 clearstack();
    72 status=Finished;
    73 aborting=true;
     66        if (file && ownfile)
     67        {
     68                delete file;
     69                file = 0;
     70        }
     71        clearstack();
     72        status = Finished;
     73        aborting = true;
    7474}
    7575
    7676void MultiParamLoader::load(VirtFILE *f)
    7777{
    78 abort();
    79 ownfile=0;
    80 file=f;
    81 load();
     78        abort();
     79        ownfile = 0;
     80        file = f;
     81        load();
    8282}
    8383
    8484void MultiParamLoader::load(const char* filename)
    8585{
    86 abort();
    87 ownfile=1;
    88 file=Vfopen(filename,FOPEN_READ_BINARY);
    89 load();
     86        abort();
     87        ownfile = 1;
     88        file = Vfopen(filename, FOPEN_READ_BINARY);
     89        load();
    9090}
    9191
    9292int MultiParamLoader::go()
    9393{
    94 SString buf;
    95 if (status==OnError) return status;
    96 int unexpected_line = 0;
    97 while (!finished())
    98         {
    99         if ((status==BeforeObject) || ((status==BeforeUnknown) && !lastobject.isEmpty()))
    100                 {
    101                 Param tmp_param;
    102                 ParamInterface *pi=lastobject.getParamInterface(tmp_param);
    103                 pi->load(file,true,&aborting,&linenum);
    104                 if ((status!=Finished) && maybeBreak(AfterObject))
    105                         break;
    106                 unexpected_line = 0;
    107                 continue;
    108                 }
    109         else if (status==BeforeUnknown)
    110                 {
    111                 logPrintf("MultiParamLoader","go",LOG_WARN,"Skipping object '%s'",lastunknown.c_str());
    112                 loadObjectNow(&emptyparam,false);
    113                 continue;
    114                 }
    115         if (!loadSStringLine(file,buf))
    116                 {
    117                 unexpected_line = 0;
    118                 if (!returnFromIncluded())
    119                         {
    120                         abort();
    121                         break;
    122                         }
    123                 else
     94        SString buf;
     95        if (status == OnError) return status;
     96        int unexpected_line = 0;
     97        while (!finished())
     98        {
     99                if ((status == BeforeObject) || ((status == BeforeUnknown) && !lastobject.isEmpty()))
     100                {
     101                        Param tmp_param;
     102                        ParamInterface *pi = lastobject.getParamInterface(tmp_param);
     103                        ParamInterface::LoadOptions opts;
     104                        opts.abortable = &aborting;
     105                        opts.warn_unknown_fields = true;
     106                        opts.linenum = &linenum;
     107                        pi->load(ParamInterface::FormatMultiLine, file, &opts);
     108                        if ((status != Finished) && maybeBreak(AfterObject))
     109                                break;
     110                        unexpected_line = 0;
    124111                        continue;
    125112                }
    126         linenum++;
    127         if (buf[0]=='#')
    128                 {
    129                 unexpected_line = 0;
    130                 if (buf.startsWith("#include"))
    131                         {
    132                         const char* t=strchr(buf.c_str(),'\"'),*t2=0;
    133                         if (t)
    134                                 t2=strchr(t+1,'\"');
    135                         if (t2)
     113                else if (status == BeforeUnknown)
     114                {
     115                        logPrintf("MultiParamLoader", "go", LOG_WARN, "Skipping object '%s'", lastunknown.c_str());
     116                        loadObjectNow(&emptyparam, false);
     117                        continue;
     118                }
     119                if (!loadSStringLine(file, buf))
     120                {
     121                        unexpected_line = 0;
     122                        if (!returnFromIncluded())
     123                        {
     124                                abort();
     125                                break;
     126                        }
     127                        else
     128                                continue;
     129                }
     130                linenum++;
     131                if (buf[0] == '#')
     132                {
     133                        unexpected_line = 0;
     134                        if (buf.startsWith("#include"))
     135                        {
     136                                const char* t = strchr(buf.c_str(), '\"'), *t2 = 0;
     137                                if (t)
     138                                        t2 = strchr(t + 1, '\"');
     139                                if (t2)
    136140                                {
    137                                 SString filename(t+1,t2-t-1);
    138                                 includeFile(filename);
     141                                        SString filename(t + 1, t2 - t - 1);
     142                                        includeFile(filename);
    139143                                }
    140                         else
     144                                else
    141145                                {
    142                                 const char* thisfilename=file->VgetPath();
    143                                 logPrintf("MultiParamLoader","go",LOG_WARN,"invalid \"%s\"%s%s",buf.c_str(),
    144                                          (thisfilename?" in ":""),(thisfilename?thisfilename:""));
     146                                        const char* thisfilename = file->VgetPath();
     147                                        logPrintf("MultiParamLoader", "go", LOG_WARN, "invalid \"%s\"%s%s", buf.c_str(),
     148                                                (thisfilename ? " in " : ""), (thisfilename ? thisfilename : ""));
    145149                                }
     150                                continue;
     151                        }
     152                        else if ((status != Finished) && maybeBreak(OnComment))
     153                        {
     154                                lastcomment = buf.substr(1);
     155                                break;
     156                        }
    146157                        continue;
    147                         }
    148                 else if ((status!=Finished) && maybeBreak(OnComment))
    149                         {
    150                         lastcomment=buf.substr(1);
    151                         break;
    152                         }
    153                 continue;
    154                 }
    155         buf=trim(buf);
    156         if (buf.len()==0)
    157                 unexpected_line = 0;
    158         else if ((buf.len()>1)&&(buf[buf.len()-1]==':'))
    159                 {
    160                 unexpected_line = 0;
    161                 lastunknown=0;
    162                 lastunknown=buf.substr(0,buf.len()-1);
    163                 lastobject.setEmpty();
    164                 FOREACH(ExtObject*,o,objects)
    165                         {
    166                         if (!strcmp(o->interfaceName(),lastunknown.c_str())) {lastobject=*o; break;}
     158                }
     159                buf = trim(buf);
     160                if (buf.len() == 0)
     161                        unexpected_line = 0;
     162                else if ((buf.len() > 1) && (buf[buf.len() - 1] == ':'))
     163                {
     164                        unexpected_line = 0;
     165                        lastunknown = 0;
     166                        lastunknown = buf.substr(0, buf.len() - 1);
     167                        lastobject.setEmpty();
     168                        FOREACH(ExtObject*, o, objects)
     169                        {
     170                                if (!strcmp(o->interfaceName(), lastunknown.c_str())) { lastobject = *o; break; }
    167171                        }
    168172                        if (!lastobject.isEmpty())
    169                                 {
     173                        {
    170174                                if (maybeBreak(BeforeObject))
    171175                                        break;
    172                                 }
     176                        }
    173177                        else
    174                                 {
     178                        {
    175179                                if (maybeBreak(BeforeUnknown))
    176180                                        break;
    177                                 }
    178                
    179                 }
     181                        }
     182
     183                }
     184                else
     185                {
     186                        switch (unexpected_line)
     187                        {
     188                        case 0:
     189                        {
     190                                const char* thisfilename = file->VgetPath();
     191                                logPrintf("MultiParamLoader", "go", LOG_WARN, "Ignored unexpected line %d%s",
     192                                        linenum,
     193                                        thisfilename ? SString::sprintf(" while reading '%s'", thisfilename).c_str() : "");
     194                        }
     195                                break;
     196
     197                        case 1:
     198                                logPrintf("MultiParamLoader", "go", LOG_WARN, "The following line(s) were also unexpected and were ignored");
     199                                break;
     200                        }
     201                        unexpected_line++;
     202                }
     203        }
     204        return status;
     205}
     206
     207bool MultiParamLoader::alreadyIncluded(const char* filename)
     208{
     209        int i;
     210        const char* t;
     211        for (i = 0; i < filestack.size(); i++)
     212        {
     213                t = filestack(i)->VgetPath();
     214                if (!t) continue;
     215                if (!strcmp(filename, t)) return true;
     216        }
     217        return false;
     218}
     219
     220void MultiParamLoader::includeFile(SString& filename)
     221{
     222        const char* thisfilename = file->VgetPath();
     223        SString newfilename;
     224        const char* t = thisfilename ? strrchr(thisfilename, PATH_SEPARATOR_CHAR) : 0;
     225
     226        if (thisfilename && t)
     227        {
     228                newfilename.append(thisfilename, t - thisfilename + 1);
     229                newfilename += filename;
     230        }
    180231        else
    181                 {
    182                 switch(unexpected_line)
    183                         {
    184                         case 0:
    185                         {
    186                         const char* thisfilename=file->VgetPath();
    187                         logPrintf("MultiParamLoader","go", LOG_WARN, "Ignored unexpected line %d%s",
    188                                   linenum,
    189                                   thisfilename ? SString::sprintf(" while reading '%s'",thisfilename).c_str():"");
    190                         }
    191                         break;
    192 
    193                         case 1:
    194                         logPrintf("MultiParamLoader","go", LOG_WARN, "The following line(s) were also unexpected and were ignored");
    195                         break;
    196                         }
    197                 unexpected_line++;
    198                 }
    199         }
    200 return status;
    201 }
    202 
    203 bool MultiParamLoader::alreadyIncluded(const char* filename)
    204 {
    205 int i;
    206 const char* t;
    207 for(i=0;i<filestack.size();i++)
    208         {
    209         t=filestack(i)->VgetPath();
    210         if (!t) continue;
    211         if (!strcmp(filename,t)) return true;
    212         }
    213 return false;
    214 }
    215 
    216 void MultiParamLoader::includeFile(SString& filename)
    217 {
    218 const char* thisfilename=file->VgetPath();
    219 SString newfilename;
    220 const char* t=thisfilename?strrchr(thisfilename,PATH_SEPARATOR_CHAR):0;
    221 
    222 if (thisfilename && t)
    223         {
    224         newfilename.append(thisfilename,t-thisfilename+1);
    225         newfilename+=filename;
    226         }
    227 else
    228         newfilename=filename;
    229 
    230 if (alreadyIncluded(newfilename.c_str()))
    231         {
    232         logPrintf("MultiParamLoader","include",LOG_WARN,"circular reference ignored (\"%s\")",
    233                     filename.c_str());
    234         return;
    235         }
    236 
    237 VirtFILE *f=Vfopen(newfilename.c_str(),FOPEN_READ_BINARY);
    238 if (!f)
    239         {
    240         logPrintf("MultiParamLoader","include",LOG_WARN,"\"%s\" not found",newfilename.c_str());
    241         }
    242 else
    243         {
    244         filestack+=file;
    245         file=f;
     232                newfilename = filename;
     233
     234        if (alreadyIncluded(newfilename.c_str()))
     235        {
     236                logPrintf("MultiParamLoader", "include", LOG_WARN, "circular reference ignored (\"%s\")",
     237                        filename.c_str());
     238                return;
     239        }
     240
     241        VirtFILE *f = Vfopen(newfilename.c_str(), FOPEN_READ_BINARY);
     242        if (!f)
     243        {
     244                logPrintf("MultiParamLoader", "include", LOG_WARN, "\"%s\" not found", newfilename.c_str());
     245        }
     246        else
     247        {
     248                filestack += file;
     249                file = f;
    246250        }
    247251}
     
    249253VirtFILE* MultiParamLoader::popstack()
    250254{
    251 if (!filestack.size()) return 0;
    252 VirtFILE* f=filestack(filestack.size()-1);
    253 filestack.remove(filestack.size()-1);
    254 return f;
     255        if (!filestack.size()) return 0;
     256        VirtFILE* f = filestack(filestack.size() - 1);
     257        filestack.remove(filestack.size() - 1);
     258        return f;
    255259}
    256260
    257261void MultiParamLoader::clearstack()
    258262{
    259 VirtFILE *f;
    260 while(f=popstack()) delete f;
     263        VirtFILE *f;
     264        while (f = popstack()) delete f;
    261265}
    262266
    263267bool MultiParamLoader::returnFromIncluded()
    264268{
    265 if (!filestack.size()) return false;
    266 if (file) delete file;
    267 file=popstack();
    268 return true;
    269 }
    270 
    271 int MultiParamLoader::loadObjectNow(const ExtObject& o,bool warn_unknown_fields)
    272 {
    273 Param tmp_param;
    274 ParamInterface *pi=o.getParamInterface(tmp_param);
    275 pi->load(file,warn_unknown_fields,&aborting,&linenum);
    276 status=AfterObject;
    277 return 0;
     269        if (!filestack.size()) return false;
     270        if (file) delete file;
     271        file = popstack();
     272        return true;
     273}
     274
     275int MultiParamLoader::loadObjectNow(const ExtObject& o, bool warn_unknown_fields)
     276{
     277        Param tmp_param;
     278        ParamInterface *pi = o.getParamInterface(tmp_param);
     279        ParamInterface::LoadOptions opts;
     280        opts.abortable = &aborting;
     281        opts.warn_unknown_fields = warn_unknown_fields;
     282        opts.linenum = &linenum;
     283        pi->load(ParamInterface::FormatMultiLine, file, &opts);
     284        status = AfterObject;
     285        return 0;
    278286}
    279287
    280288int MultiParamLoader::run()
    281289{
    282 int stat;
    283 breakOn(OnError);
    284 while(stat=go())
    285         if (stat==OnError)
     290        int stat;
     291        breakOn(OnError);
     292        while (stat = go())
     293                if (stat == OnError)
    286294                {
    287295                abort();
    288296                return 0;
    289297                }
    290 return 1;
     298        return 1;
    291299}
    292300
    293301SString MultiParamLoader::currentFilePathForErrorMessage()
    294302{
    295 const char* filename=getFile()->VgetPath();
    296 if (filename)
    297         return SString::sprintf(" in '%s'",filename);
    298 return SString::empty();
    299 }
     303        const char* filename = getFile()->VgetPath();
     304        if (filename)
     305                return SString::sprintf(" in '%s'", filename);
     306        return SString::empty();
     307}
  • cpp/frams/param/param.cpp

    r704 r720  
    1010#include "common/log.h"
    1111#include <frams/util/sstringutils.h>
     12#include <common/virtfile/stringfile.h>
    1213
    1314//#define SAVE_ALL_NAMES
     
    356357}
    357358
    358 void SimpleAbstractParam::save2(SString& f, void *defdata, bool addcr, bool all_names)
     359void SimpleAbstractParam::saveSingleLine(SString& f, void *defdata, bool addcr, bool all_names)
    359360{ // defdata!=NULL -> does not save default values
    360361        const char *p;
     
    421422}
    422423
    423 int ParamInterface::load(VirtFILE* f, bool warn_unknown_fields, bool *abortable, int *linenum)
     424int ParamInterface::load(FileFormat format, VirtFILE* f, LoadOptions *options)
     425{
     426        LoadOptions default_options;
     427        if (options == NULL)
     428                options = &default_options;
     429        switch (format)
     430        {
     431        case FormatMultiLine:
     432                return loadMultiLine(f, *options);
     433
     434        case FormatSingleLine:
     435        {
     436                StringFILE *sf = dynamic_cast<StringFILE*>(f);
     437                SString s;
     438                if (sf)
     439                {
     440                        s = sf->getString().c_str();
     441                        options->offset += sf->Vtell();
     442                }
     443                else
     444                {
     445                        if (!loadSStringLine(f, s))
     446                                return -1;
     447                }
     448                return loadSingleLine(s, *options);
     449        }
     450        }
     451        return -1;
     452}
     453
     454int ParamInterface::load(FileFormat format, const SString &s, LoadOptions *options)
     455{
     456        LoadOptions default_options;
     457        if (options == NULL)
     458                options = &default_options;
     459        switch (format)
     460        {
     461        case FormatMultiLine:
     462        {
     463                string std_string(s.c_str());
     464                StringFILE f(std_string);
     465                return loadMultiLine(&f, *options);
     466        }
     467
     468        case FormatSingleLine:
     469                return loadSingleLine(s, *options);
     470        }
     471        return -1;
     472}
     473
     474int ParamInterface::loadMultiLine(VirtFILE* f, LoadOptions &options)
    424475{
    425476        SString buf;
     
    434485        if ((i = findId("beforeLoad")) >= 0)
    435486                call(i, NULL, NULL);
    436         while (((!abortable) || (!*abortable)) && loadSStringLine(f, buf))
    437         {
    438                 if (linenum) (*linenum)++;
     487        while (((!options.abortable) || (!*options.abortable)) && loadSStringLine(f, buf))
     488        {
     489                if (options.linenum) (*options.linenum)++;
    439490                const char* t = buf.c_str();
    440491                p0 = t; while (isblank(*p0)) p0++;
     
    448499                        case 0:
    449500                                logPrintf("ParamInterface", "load", LOG_WARN, "Ignored unexpected line %s while reading object '%s'",
    450                                         linenum ?
    451                                         SString::sprintf("%d", *linenum).c_str()
     501                                        options.linenum ?
     502                                        SString::sprintf("%d", *options.linenum).c_str()
    452503                                        : SString::sprintf("'%s'", p0).c_str(),
    453504                                        getName());
     
    472523                                {
    473524                                        fileinfo = SString::sprintf(" while reading from '%s'", fname);
    474                                         if (linenum)
    475                                                 fileinfo += SString::sprintf(" (line %d)", *linenum);
     525                                        if (options.linenum)
     526                                                fileinfo += SString::sprintf(" (line %d)", *options.linenum);
    476527                                }
    477528                                logPrintf("ParamInterface", "load", LOG_WARN, "Multiple '%s.%s' fields found%s", getName(), id(i), fileinfo.c_str());
     
    496547                                        int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break;
    497548                                        unquoteTilde(s);
    498                                         if (linenum && (flags(i)&PARAM_LINECOMMENT))
    499                                                 s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *linenum + 1) + s;
     549                                        if (options.linenum && (flags(i)&PARAM_LINECOMMENT))
     550                                                s = SString::sprintf("@file %s\n@line %d\n", f->VgetPath(), *options.linenum + 1) + s;
    500551                                        set(i, s.c_str());
    501                                         if (linenum)
    502                                                 (*linenum) += lfcount;
     552                                        if (options.linenum)
     553                                                (*options.linenum) += lfcount;
    503554                                }
    504555                                else
     
    510561                        }
    511562                }
    512                 else if (warn_unknown_fields)
     563                else if (options.warn_unknown_fields)
    513564                {
    514565                        SString name(p0, p_len);
     
    521572                        if (!readUntilTilde(f, s))
    522573                                closingTildeError(this, f, -1);
    523                         if (linenum)
     574                        if (options.linenum)
    524575                        {
    525576                                const char* tmp = s.c_str();
     
    530581                                        lfcount++; tmp++;
    531582                                        }
    532                                 (*linenum) += lfcount;
     583                                (*options.linenum) += lfcount;
    533584                        }
    534585                        int ch; while ((ch = f->Vgetc()) != EOF) if (ch == '\n') break;
     
    705756{
    706757        const char *t;
    707         if (((*(t = type(i))) == 'd') && (strchr(t, '~')!=NULL)) //type is int and contains enum labels
     758        if (((*(t = type(i))) == 'd') && (strchr(t, '~') != NULL)) //type is int and contains enum labels
    708759        {
    709760                paInt mn, mx, def;
     
    11311182}
    11321183
    1133 int ParamInterface::load2(const SString &s, int &poz)
     1184int ParamInterface::loadSingleLine(const SString &s, LoadOptions &options)
    11341185{
    11351186        int i; // the index number of the parameter
     
    11451196        SString tmpvalue;
    11461197        bool parse_failed = false;
    1147         if (poz >= s.len()) return fields_loaded;
    1148         t = s.c_str() + poz;
    1149 
    1150         lin = getline(s, poz, len); // all fields must be encoded in a single line
     1198        if (options.offset >= s.len()) return fields_loaded;
     1199        t = s.c_str() + options.offset;
     1200
     1201        lin = getline(s, options.offset, len); // all fields must be encoded in a single line
    11511202        if (!len) return fields_loaded; // empty line = end
    11521203        i = 0;
     
    12411292#endif
    12421293        }
    1243         return fields_loaded | (parse_failed ? LOAD2_PARSE_FAILED : 0);
     1294        if (parse_failed) options.parse_failed = true;
     1295        return fields_loaded;
    12441296}
    12451297
  • cpp/frams/param/param.h

    r650 r720  
    2828#define PARAM_NOSTATIC  256     //< (FramScript) don't access this member in a static object (ClassName.field)
    2929#define PARAM_CONST     512     //< (FramScript) constant value
    30 #define PARAM_CANOMITNAME 1024  //< affects Param::save2()/load2() - for example one-liners in f0 genetic encoding
     30#define PARAM_CANOMITNAME 1024  //< affects Param::saveSingleLine()/loadSingleLine() - for example one-liners in f0 genetic encoding
    3131#define PARAM_DONTLOAD    2048  //< Param::load() skips this field
    3232#define PARAM_NOISOLATION 4096  //< don't use proxy object in master/slave interactions
     
    170170        void quickCopyFrom(ParamInterface *src);
    171171
     172        enum FileFormat { FormatMultiLine, FormatSingleLine }; // FormatJSON in the future?
     173        struct LoadOptions {
     174                bool warn_unknown_fields; bool *abortable; int *linenum; int offset; bool parse_failed;
     175                LoadOptions() : warn_unknown_fields(false), abortable(NULL), linenum(NULL), offset(0), parse_failed(false) {}
     176        };
     177
    172178        int save(VirtFILE*, const char* altname = NULL, bool force = 0);
    173179        int saveprop(VirtFILE*, int i, const char* p, bool force = 0);
    174         int load(VirtFILE*, bool warn_unknown_fields = true, bool *abortable = NULL, int *linenum = NULL);///< @return the number of fields loaded
    175         int load2(const SString &, int &);///< @return the number of fields loaded (or'ed with LOAD2_PARSE_FAILED if a parsing error was detected)
     180
     181        int load(FileFormat format, VirtFILE*, LoadOptions *load_options = NULL);///< @return the number of fields loaded
     182        int load(FileFormat format, const SString &, LoadOptions *load_options = NULL);///< @return the number of fields loaded
     183protected:
     184        int loadMultiLine(VirtFILE*, LoadOptions &options);///< @return the number of fields loaded
     185        int loadSingleLine(const SString &, LoadOptions &options);///< @return the number of fields loaded
     186public:
    176187
    177188        static const char* SERIALIZATION_PREFIX;
    178         static const int LOAD2_PARSE_FAILED = (1 << 30); ///< this bit is set in return value from load2 if a parse error was detected while loading. usage: if (load2(...) & LOAD2_PARSE_FAILED) ...
    179         static const int LOAD2_IGNORE_PARSE_FAILED = (~LOAD2_PARSE_FAILED); ///< bitmask to be used if the parsing error is to be ignored. usage: int number_of_loaded_fields=load2(...) & LOAD2_IGNORE_PARSE_FAILED;
    180189
    181190        static bool isValidTypeDescription(const char* t);
     
    299308
    300309        int isequal(int i, void* defdata);
    301         void save2(SString&, void *defdata, bool addcr = true, bool all_names = true);
     310        void saveSingleLine(SString&, void *defdata, bool addcr = true, bool all_names = true);
    302311
    303312        virtual void setDefault();
  • cpp/frams/param/syntparam.cpp

    r286 r720  
    88#include <math.h>
    99
    10 SyntParam::SyntParam(ParamEntry *init_pe,SString* autostr,bool handle_defaults_when_saving)
     10SyntParam::SyntParam(ParamEntry *init_pe, SString* autostr, bool handle_defaults_when_saving)
    1111        :autostring(autostr)
    1212{
    13 Param::setParamTab(init_pe);
    14 pe=ParamObject::makeParamTab(this);
    15 Param::setParamTab(pe);
    16 if (handle_defaults_when_saving)
     13        Param::setParamTab(init_pe);
     14        pe = ParamObject::makeParamTab(this);
     15        Param::setParamTab(pe);
     16        if (handle_defaults_when_saving)
    1717        {
    18         def_obj=ParamObject::makeObject(pe);
    19         Param::select(def_obj);
     18                def_obj = ParamObject::makeObject(pe);
     19                Param::select(def_obj);
     20                Param::setDefault();
     21        }
     22        else
     23                def_obj = NULL;
     24        obj = ParamObject::makeObject(pe);
     25        Param::select(obj);
    2026        Param::setDefault();
    21         }
    22 else
    23         def_obj=NULL;
    24 obj=ParamObject::makeObject(pe);
    25 Param::select(obj);
    26 Param::setDefault();
    27 revert();
     27        revert();
    2828}
    2929
    3030SyntParam::SyntParam(const SyntParam& src)
    31         :Param(),autostring(src.autostring)
     31        :Param(), autostring(src.autostring)
    3232{
    33 Param::setParamTab(src.pe);
    34 pe=ParamObject::makeParamTab(this);
    35 Param::setParamTab(pe);
    36 obj=ParamObject::dupObject(src.obj);
    37 def_obj=src.def_obj ? ParamObject::dupObject(src.def_obj) : NULL;
    38 Param::select(obj);
     33        Param::setParamTab(src.pe);
     34        pe = ParamObject::makeParamTab(this);
     35        Param::setParamTab(pe);
     36        obj = ParamObject::dupObject(src.obj);
     37        def_obj = src.def_obj ? ParamObject::dupObject(src.def_obj) : NULL;
     38        Param::select(obj);
    3939}
    4040
    4141SyntParam::~SyntParam()
    4242{
    43 update();
    44 ParamObject::freeParamTab(pe);
    45 ParamObject::freeObject(obj);
    46 ParamObject::freeObject(def_obj);
     43        update();
     44        ParamObject::freeParamTab(pe);
     45        ParamObject::freeObject(obj);
     46        ParamObject::freeObject(def_obj);
    4747}
    4848
    4949void SyntParam::update(SString *s)
    5050{
    51 if (!s) s=autostring;
    52 if (s) {*s=""; Param::save2(*s,def_obj,0);}
     51        if (!s) s = autostring;
     52        if (s) { *s = ""; Param::saveSingleLine(*s, def_obj, 0); }
    5353}
    5454
    5555void SyntParam::revert(SString *s)
    5656{
    57 if (!s) s=autostring;
    58 if (s)  {
    59         int p=0;
    60         Param::load2(*s,p);
     57        if (!s) s = autostring;
     58        if (s)  {
     59                Param::load(ParamInterface::FormatSingleLine, *s);
    6160        }
    6261}
    63 
    64 
    65 
    66 
    67 
Note: See TracChangeset for help on using the changeset viewer.