From 97926eb08cf74f277e522ffb8c7f985457822de3 Mon Sep 17 00:00:00 2001 From: Thomas Grill Date: Tue, 11 Feb 2003 04:37:35 +0000 Subject: "" svn path=/trunk/; revision=388 --- externals/grill/pool/main.cpp | 225 +++++++++++++++++++++++++++++++----------- 1 file changed, 166 insertions(+), 59 deletions(-) (limited to 'externals/grill/pool/main.cpp') diff --git a/externals/grill/pool/main.cpp b/externals/grill/pool/main.cpp index cf513d87..4397a55b 100644 --- a/externals/grill/pool/main.cpp +++ b/externals/grill/pool/main.cpp @@ -10,7 +10,10 @@ WARRANTIES, see the file, "license.txt," in this distribution. #include "pool.h" -#define POOL_VERSION "0.1.1pre" +#define POOL_VERSION "0.2.0pre" + +#define VCNT 64 +#define DCNT 16 class pool: public flext_base @@ -22,6 +25,8 @@ public: ~pool(); static V setup(t_classid); + + virtual BL Init(); pooldata *Pool() { return pl; } @@ -58,6 +63,9 @@ protected: V m_getall(); // only values V m_getrec(I argc,const A *argv); // also subdirectories V m_getsub(I argc,const A *argv); // only subdirectories + V m_ogetall(); // only values (ordered) + V m_ogetrec(I argc,const A *argv); // also subdirectories (ordered) + V m_ogetsub(I argc,const A *argv); // only subdirectories (ordered) V m_cntall(); // only values V m_cntrec(I argc,const A *argv); // also subdirectories V m_cntsub(I argc,const A *argv); // only subdirectories @@ -74,16 +82,22 @@ protected: V m_copyrec(I argc,const A *argv) { copyrec(MakeSymbol("copyrec"),argc,argv,false); } // cut directory (and subdirs) into clipboard // load/save from/to file - V m_load(I argc,const A *argv); - V m_save(I argc,const A *argv); + V m_load(I argc,const A *argv) { load(argc,argv,false); } + V m_save(I argc,const A *argv) { save(argc,argv,false); } + V m_loadx(I argc,const A *argv) { load(argc,argv,true); } // XML + V m_savex(I argc,const A *argv) { save(argc,argv,true); } // XML // load directories - V m_lddir(I argc,const A *argv); // load values into current dir - V m_ldrec(I argc,const A *argv); // load values recursively + V m_lddir(I argc,const A *argv) { lddir(argc,argv,false); } // load values into current dir + V m_ldrec(I argc,const A *argv) { ldrec(argc,argv,false); } // load values recursively + V m_ldxdir(I argc,const A *argv) { lddir(argc,argv,true); } // load values into current dir (XML) + V m_ldxrec(I argc,const A *argv) { ldrec(argc,argv,true); } // load values recursively (XML) // save directories - V m_svdir(I argc,const A *argv); // save values in current dir - V m_svrec(I argc,const A *argv); // save values recursively + V m_svdir(I argc,const A *argv) { svdir(argc,argv,false); } // save values in current dir + V m_svrec(I argc,const A *argv) { svrec(argc,argv,false); } // save values recursively + V m_svxdir(I argc,const A *argv) { svdir(argc,argv,true); } // save values in current dir (XML) + V m_svxrec(I argc,const A *argv) { svrec(argc,argv,true); } // save values recursively (XML) private: static BL KeyChk(const A &a); @@ -93,20 +107,29 @@ private: V set(const S *tag,I argc,const A *argv,BL over); V getdir(const S *tag); - I getrec(const S *tag,I level,BL cntonly = false,const AtomList &rdir = AtomList()); - I getsub(const S *tag,I level,BL cntonly = false,const AtomList &rdir = AtomList()); + I getrec(const S *tag,I level,BL order,BL cntonly = false,const AtomList &rdir = AtomList()); + I getsub(const S *tag,I level,BL order,BL cntonly = false,const AtomList &rdir = AtomList()); V paste(const S *tag,I argc,const A *argv,BL repl); V copy(const S *tag,I argc,const A *argv,BL cut); V copyall(const S *tag,BL cut,I lvls); V copyrec(const S *tag,I argc,const A *argv,BL cut); + V load(I argc,const A *argv,BL xml); + V save(I argc,const A *argv,BL xml); + V lddir(I argc,const A *argv,BL xml); // load values into current dir + V ldrec(I argc,const A *argv,BL xml); // load values recursively + V svdir(I argc,const A *argv,BL xml); // save values in current dir + V svrec(I argc,const A *argv,BL xml); // save values recursively + V echodir() { if(echo) getdir(MakeSymbol("echo")); } BL priv,absdir,echo; + I vcnt,dcnt; pooldata *pl; AtomList curdir; pooldir *clip; + const S *holdname; static pooldata *head,*tail; @@ -121,6 +144,8 @@ private: FLEXT_ATTRVAR_B(echo) FLEXT_ATTRGET_B(priv) // FLEXT_ATTRGET_B(curdir) + FLEXT_ATTRVAR_I(vcnt) + FLEXT_ATTRVAR_I(dcnt) FLEXT_CALLBACK(m_reset) @@ -144,6 +169,9 @@ private: FLEXT_CALLBACK(m_getall) FLEXT_CALLBACK_V(m_getrec) FLEXT_CALLBACK_V(m_getsub) + FLEXT_CALLBACK(m_ogetall) + FLEXT_CALLBACK_V(m_ogetrec) + FLEXT_CALLBACK_V(m_ogetsub) FLEXT_CALLBACK(m_cntall) FLEXT_CALLBACK_V(m_cntrec) FLEXT_CALLBACK_V(m_cntsub) @@ -164,6 +192,12 @@ private: FLEXT_CALLBACK_V(m_ldrec) FLEXT_CALLBACK_V(m_svdir) FLEXT_CALLBACK_V(m_svrec) + FLEXT_CALLBACK_V(m_loadx) + FLEXT_CALLBACK_V(m_savex) + FLEXT_CALLBACK_V(m_ldxdir) + FLEXT_CALLBACK_V(m_ldxrec) + FLEXT_CALLBACK_V(m_svxdir) + FLEXT_CALLBACK_V(m_svxrec) }; FLEXT_NEW_V("pool",pool); @@ -175,7 +209,7 @@ pooldata *pool::head,*pool::tail; V pool::setup(t_classid c) { post(""); - post("pool %s - hierarchical storage object, (C)2002 Thomas Grill",POOL_VERSION); + post("pool %s - hierarchical storage object,(C)2002-2003 Thomas Grill",POOL_VERSION); post(""); head = tail = NULL; @@ -184,6 +218,8 @@ V pool::setup(t_classid c) FLEXT_CADDATTR_VAR1(c,"absdir",absdir); FLEXT_CADDATTR_VAR1(c,"echodir",echo); FLEXT_CADDATTR_GET(c,"private",priv); + FLEXT_CADDATTR_VAR1(c,"valcnt",vcnt); + FLEXT_CADDATTR_VAR1(c,"dircnt",dcnt); FLEXT_CADDMETHOD_(c,0,"reset",m_reset); FLEXT_CADDMETHOD_(c,0,"set",m_set); @@ -207,6 +243,9 @@ V pool::setup(t_classid c) FLEXT_CADDMETHOD_(c,0,"getall",m_getall); FLEXT_CADDMETHOD_(c,0,"getrec",m_getrec); FLEXT_CADDMETHOD_(c,0,"getsub",m_getsub); + FLEXT_CADDMETHOD_(c,0,"ogetall",m_ogetall); + FLEXT_CADDMETHOD_(c,0,"ogetrec",m_ogetrec); + FLEXT_CADDMETHOD_(c,0,"ogetsub",m_ogetsub); FLEXT_CADDMETHOD_(c,0,"cntall",m_cntall); FLEXT_CADDMETHOD_(c,0,"cntrec",m_cntrec); FLEXT_CADDMETHOD_(c,0,"cntsub",m_cntsub); @@ -227,13 +266,20 @@ V pool::setup(t_classid c) FLEXT_CADDMETHOD_(c,0,"ldrec",m_ldrec); FLEXT_CADDMETHOD_(c,0,"svdir",m_svdir); FLEXT_CADDMETHOD_(c,0,"svrec",m_svrec); + FLEXT_CADDMETHOD_(c,0,"loadx",m_loadx); + FLEXT_CADDMETHOD_(c,0,"savex",m_savex); + FLEXT_CADDMETHOD_(c,0,"ldxdir",m_ldxdir); + FLEXT_CADDMETHOD_(c,0,"ldxrec",m_ldxrec); + FLEXT_CADDMETHOD_(c,0,"svxdir",m_svxdir); + FLEXT_CADDMETHOD_(c,0,"svxrec",m_svxrec); } pool::pool(I argc,const A *argv): absdir(true),echo(false),pl(NULL), - clip(NULL) + clip(NULL), + vcnt(VCNT),dcnt(DCNT) { - SetPool(argc >= 1 && IsSymbol(argv[0])?GetSymbol(argv[0]):NULL); + holdname = argc >= 1 && IsSymbol(argv[0])?GetSymbol(argv[0]):NULL; AddInAnything(); AddOutList(); @@ -247,6 +293,15 @@ pool::~pool() FreePool(); } +BL pool::Init() +{ + if(flext_base::Init()) { + SetPool(holdname); + return true; + } + else return false; +} + V pool::SetPool(const S *s) { if(pl) FreePool(); @@ -257,7 +312,7 @@ V pool::SetPool(const S *s) } else { priv = true; - pl = new pooldata; + pl = new pooldata(NULL,vcnt,dcnt); } } @@ -316,7 +371,7 @@ V pool::m_mkdir(I argc,const A *argv,BL abs) AtomList ndir; if(abs) ndir(argc,argv); else (ndir = curdir).Append(argc,argv); - if(!pl->MkDir(ndir)) { + if(!pl->MkDir(ndir,vcnt,dcnt)) { post("%s - mkdir: directory couldn't be created",thisName()); } } @@ -491,7 +546,7 @@ V pool::m_geti(I ix) echodir(); } -I pool::getrec(const S *tag,I level,BL cntonly,const AtomList &rdir) +I pool::getrec(const S *tag,I level,BL order,BL cntonly,const AtomList &rdir) { AtomList gldir(curdir); gldir.Append(rdir); @@ -527,7 +582,7 @@ I pool::getrec(const S *tag,I level,BL cntonly,const AtomList &rdir) else { I lv = level > 0?level-1:-1; for(I i = 0; i < cnt; ++i) { - ret += getrec(tag,lv,cntonly,AtomList(rdir).Append(*r[i])); + ret += getrec(tag,lv,order,cntonly,AtomList(rdir).Append(*r[i])); } delete[] r; } @@ -538,7 +593,15 @@ I pool::getrec(const S *tag,I level,BL cntonly,const AtomList &rdir) V pool::m_getall() { - getrec(MakeSymbol("getall"),0); + getrec(MakeSymbol("getall"),0,false); + ToOutBang(3); + + echodir(); +} + +V pool::m_ogetall() +{ + getrec(MakeSymbol("ogetall"),0,true); ToOutBang(3); echodir(); @@ -556,21 +619,41 @@ V pool::m_getrec(I argc,const A *argv) else post("%s - getrec: invalid level specification - set to infinite",thisName()); } - getrec(MakeSymbol("getrec"),lvls); + getrec(MakeSymbol("getrec"),lvls,false); + ToOutBang(3); + + echodir(); +} + + +V pool::m_ogetrec(I argc,const A *argv) +{ + I lvls = -1; + if(argc > 0) { + if(CanbeInt(argv[0])) { + if(argc > 1) + post("%s - ogetrec: superfluous arguments ignored",thisName()); + lvls = GetAInt(argv[0]); + } + else + post("%s - ogetrec: invalid level specification - set to infinite",thisName()); + } + getrec(MakeSymbol("ogetrec"),lvls,true); ToOutBang(3); echodir(); } -I pool::getsub(const S *tag,I level,BL cntonly,const AtomList &rdir) +I pool::getsub(const S *tag,I level,BL order,BL cntonly,const AtomList &rdir) { AtomList gldir(curdir); gldir.Append(rdir); I ret = 0; - const A **r; + const A **r = NULL; + // CntSub is not used here because it doesn't allow checking for valid directory I cnt = pl->GetSub(gldir,r); if(!r) post("%s - %s: error retrieving directories",thisName(),GetString(tag)); @@ -588,7 +671,7 @@ I pool::getsub(const S *tag,I level,BL cntonly,const AtomList &rdir) } if(level != 0) - ret += getsub(tag,lv,cntonly,AtomList(rdir).Append(*r[i])); + ret += getsub(tag,lv,order,cntonly,AtomList(rdir).Append(*r[i])); } delete[] r; } @@ -609,7 +692,27 @@ V pool::m_getsub(I argc,const A *argv) post("%s - getsub: invalid level specification - set to 0",thisName()); } - getsub(MakeSymbol("getsub"),lvls); + getsub(MakeSymbol("getsub"),lvls,false); + ToOutBang(3); + + echodir(); +} + + +V pool::m_ogetsub(I argc,const A *argv) +{ + I lvls = 0; + if(argc > 0) { + if(CanbeInt(argv[0])) { + if(argc > 1) + post("%s - ogetsub: superfluous arguments ignored",thisName()); + lvls = GetAInt(argv[0]); + } + else + post("%s - ogetsub: invalid level specification - set to 0",thisName()); + } + + getsub(MakeSymbol("ogetsub"),lvls,true); ToOutBang(3); echodir(); @@ -619,7 +722,7 @@ V pool::m_getsub(I argc,const A *argv) V pool::m_cntall() { const S *tag = MakeSymbol("cntall"); - I cnt = getrec(tag,0,true); + I cnt = getrec(tag,0,false,true); ToOutSymbol(3,tag); ToOutBang(2); ToOutBang(1); @@ -643,7 +746,7 @@ V pool::m_cntrec(I argc,const A *argv) post("%s - %s: invalid level specification - set to infinite",thisName(),GetString(tag)); } - I cnt = getrec(tag,lvls,true); + I cnt = getrec(tag,lvls,false,true); ToOutSymbol(3,tag); ToOutBang(2); ToOutBang(1); @@ -668,7 +771,7 @@ V pool::m_cntsub(I argc,const A *argv) post("%s - %s: invalid level specification - set to 0",thisName(),GetString(tag)); } - I cnt = getsub(tag,lvls,true); + I cnt = getsub(tag,lvls,false,true); ToOutSymbol(3,tag); ToOutBang(2); ToOutBang(1); @@ -760,58 +863,60 @@ V pool::copyrec(const S *tag,I argc,const A *argv,BL cut) copyall(tag,cut,lvls); } -V pool::m_load(I argc,const A *argv) +V pool::load(I argc,const A *argv,BL xml) { + const C *sym = xml?"loadx":"load"; const C *flnm = NULL; if(argc > 0) { - if(argc > 1) post("%s - load: superfluous arguments ignored",thisName()); + if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),sym); if(IsString(argv[0])) flnm = GetString(argv[0]); } if(!flnm) - post("%s - load: no filename given",thisName()); - else if(!pl->Load(flnm)) - post("%s - load: error loading data",thisName()); + post("%s - %s: no filename given",thisName(),sym); + else if(!(xml?pl->LoadXML(flnm):pl->Load(flnm))) + post("%s - %s: error loading data",thisName(),sym); echodir(); } -V pool::m_save(I argc,const A *argv) +V pool::save(I argc,const A *argv,BL xml) { + const C *sym = xml?"savex":"save"; const C *flnm = NULL; if(argc > 0) { - if(argc > 1) post("%s - save: superfluous arguments ignored",thisName()); + if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),sym); if(IsString(argv[0])) flnm = GetString(argv[0]); } if(!flnm) - post("%s - save: no filename given",thisName()); - else if(!pl->Save(flnm)) - post("%s - save: error saving data",thisName()); + post("%s - %s: no filename given",thisName(),sym); + else if(!(xml?pl->SaveXML(flnm):pl->Save(flnm))) + post("%s - %s: error saving data",thisName(),sym); echodir(); } -V pool::m_lddir(I argc,const A *argv) +V pool::lddir(I argc,const A *argv,BL xml) { + const C *sym = xml?"ldxdir":"lddir"; const C *flnm = NULL; if(argc > 0) { - if(argc > 1) post("%s - lddir: superfluous arguments ignored",thisName()); + if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),sym); if(IsString(argv[0])) flnm = GetString(argv[0]); } if(!flnm) - post("%s - lddir: invalid filename",thisName()); - else { - if(!pl->LdDir(curdir,flnm,0)) - post("%s - lddir: directory couldn't be loaded",thisName()); - } + post("%s - %s: invalid filename",thisName(),sym); + else if(!(xml?pl->LdDirXML(curdir,flnm,0):pl->LdDir(curdir,flnm,0))) + post("%s - %s: directory couldn't be loaded",thisName(),sym); echodir(); } -V pool::m_ldrec(I argc,const A *argv) +V pool::ldrec(I argc,const A *argv,BL xml) { + const C *sym = xml?"ldxrec":"ldrec"; const C *flnm = NULL; I depth = -1; BL mkdir = true; @@ -821,59 +926,61 @@ V pool::m_ldrec(I argc,const A *argv) if(argc >= 2) { if(CanbeInt(argv[1])) depth = GetAInt(argv[1]); else - post("%s - ldrec: invalid depth argument - set to -1",thisName()); + post("%s - %s: invalid depth argument - set to -1",thisName(),sym); if(argc >= 3) { if(CanbeBool(argv[2])) mkdir = GetABool(argv[2]); else - post("%s - ldrec: invalid mkdir argument - set to true",thisName()); + post("%s - %s: invalid mkdir argument - set to true",thisName(),sym); - if(argc > 3) post("%s - ldrec: superfluous arguments ignored",thisName()); + if(argc > 3) post("%s - %s: superfluous arguments ignored",thisName(),sym); } } } if(!flnm) - post("%s - ldrec: invalid filename",thisName()); + post("%s - %s: invalid filename",thisName(),sym); else { - if(!pl->LdDir(curdir,flnm,depth,mkdir)) - post("%s - ldrec: directory couldn't be saved",thisName()); + if(!(xml?pl->LdDirXML(curdir,flnm,depth,mkdir):pl->LdDir(curdir,flnm,depth,mkdir))) + post("%s - %s: directory couldn't be saved",thisName(),sym); } echodir(); } -V pool::m_svdir(I argc,const A *argv) +V pool::svdir(I argc,const A *argv,BL xml) { + const C *sym = xml?"svxdir":"svdir"; const C *flnm = NULL; if(argc > 0) { - if(argc > 1) post("%s - svdir: superfluous arguments ignored",thisName()); + if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),sym); if(IsString(argv[0])) flnm = GetString(argv[0]); } if(!flnm) - post("%s - svdir: invalid filename",thisName()); + post("%s - %s: invalid filename",thisName(),sym); else { - if(!pl->SvDir(curdir,flnm,0,absdir)) - post("%s - svdir: directory couldn't be saved",thisName()); + if(!(xml?pl->SvDirXML(curdir,flnm,0,absdir):pl->SvDir(curdir,flnm,0,absdir))) + post("%s - %s: directory couldn't be saved",thisName(),sym); } echodir(); } -V pool::m_svrec(I argc,const A *argv) +V pool::svrec(I argc,const A *argv,BL xml) { + const C *sym = xml?"svxrec":"svrec"; const C *flnm = NULL; if(argc > 0) { - if(argc > 1) post("%s - svrec: superfluous arguments ignored",thisName()); + if(argc > 1) post("%s - %s: superfluous arguments ignored",thisName(),sym); if(IsString(argv[0])) flnm = GetString(argv[0]); } if(!flnm) - post("%s - svrec: invalid filename",thisName()); + post("%s - %s: invalid filename",thisName(),sym); else { - if(!pl->SvDir(curdir,flnm,-1,absdir)) - post("%s - svrec: directory couldn't be saved",thisName()); + if(!(xml?pl->SvDirXML(curdir,flnm,-1,absdir):pl->SvDir(curdir,flnm,-1,absdir))) + post("%s - %s: directory couldn't be saved",thisName(),sym); } echodir(); -- cgit v1.2.1