Changeset 7386


Ignore:
Timestamp:
2004-05-24T16:39:27+12:00 (20 years ago)
Author:
davidb
Message:

Modifications to macro data-structures to support collection specific
macros that override existing macros and allow for the introduction
of new collection specific ones.

Main change has been to rename 'defaultmacro_t' to 'parammacro_t' since
there are now two member fields in displayclass that use this: one
for default macros, and another for collection macros.

Location:
trunk/gsdl/lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/lib/display.cpp

    r6021 r7386  
    4343
    4444
    45 // macro value structure
    46 struct mvalue
    47 {
    48   text_t filename;
    49   text_t value;
    50 };
    5145
    5246inline bool operator==(const mvalue &x, const mvalue &y) {
     
    6256
    6357/////////////////////////////////////
    64 // stuff for defaultmacros_t
     58// stuff for parammacros_t
    6559/////////////////////////////////////
    6660 
     
    6963typedef map<text_t, defmacromap, lttext_t> defpackagemap;
    7064
    71 // all methods in defaultmacros_t assume the parameters
     65// all methods in parammacros_t assume the parameters
    7266// and packages in a standard form and not empty
    73 class defaultmacros_t
     67class parammacros_t
    7468{
    7569protected:
     
    118112//            -3 if it redefined a macro and hid a Global macro
    119113//            -4 if either a package, macroname, or params were not supplied
    120 int defaultmacros_t::setmacro(const text_t &package,
     114int parammacros_t::setmacro(const text_t &package,
    121115             const text_t &macroname,
    122116             const text_t &params,
     
    158152}
    159153
    160 void defaultmacros_t::delmacro(const text_t &package,
     154void parammacros_t::delmacro(const text_t &package,
    161155                 const text_t &macroname,
    162156                 const text_t &params)
     
    177171}
    178172
    179 defmacromap *defaultmacros_t::package_find (const text_t &packagename)
     173defmacromap *parammacros_t::package_find (const text_t &packagename)
    180174{
    181175  if (packagename.empty()) return NULL;
     
    187181}
    188182
    189 defparammap *defaultmacros_t::macro_find (const text_t &packagename,
     183defparammap *parammacros_t::macro_find (const text_t &packagename,
    190184                           const text_t &macroname)
    191185{
     
    199193}
    200194
    201 mvalue *defaultmacros_t::parameter_find (const text_t &packagename,
     195mvalue *parammacros_t::parameter_find (const text_t &packagename,
    202196                     const text_t &macroname,
    203197                     const text_t &parametername)
     
    574568displayclass::displayclass ()
    575569{
    576   defaultmacros = new defaultmacros_t;
    577   defaultfiles = new fileinfomap;
     570  defaultmacros    = new parammacros_t;
     571  collectionmacros = new parammacros_t;
     572  defaultfiles     = new fileinfomap;
    578573 
    579574  orderparamlist = new paramspeclist;
     
    589584{
    590585  delete defaultmacros;
     586  delete collectionmacros;
    591587  delete defaultfiles;
    592588 
     
    602598//        -4 if no macroname was supplied
    603599int displayclass::setdefaultmacro (text_t package, const text_t &macroname,
    604                   text_t params, const text_t &macrovalue)
    605 {
     600                   text_t params, const text_t &macrovalue)
     601{
     602  // **** Looks to me like the last two parameters are the wrong way around!!!
    606603  return setdefaultmacro (macroname, package, params, macrovalue, "memory");
    607604}
     
    686683
    687684
    688 // loads a default macro file (if it isn't already loaded)
     685// loads a macro file into the specified macrotable datastructure
    689686// returns 0 if didn't need to load the file (it was already loaded)
    690687//         1 if was (re)loaded
    691688//        -1 an error occurred while trying to load the file
    692 int displayclass::loaddefaultmacros (text_t thisfilename) {
     689int displayclass::loadparammacros (parammacros_t* macrotable, text_t thisfilename) {
    693690  // convert the filename to a C string
    694691  char *filenamestr = thisfilename.getcstr();
     
    835832     
    836833      // define the macro
    837       err = setdefaultmacro (macropackage, macroname, macroparameters,
    838                  thisfilename, macrovalue);
     834
     835      err = setparammacro (macrotable, macropackage, macroname, macroparameters,
     836                   thisfilename, macrovalue);
    839837      if ((err == -1 || err == -3) && logout != NULL) {
    840838        (*logout) << text_t2ascii << "Warning: redefinition of _" <<
     
    906904}
    907905
     906
     907// loads a default macro file (if it isn't already loaded)
     908// returns 0 if didn't need to load the file (it was already loaded)
     909//         1 if was (re)loaded
     910//        -1 an error occurred while trying to load the file
     911int displayclass::loaddefaultmacros (text_t thisfilename)
     912{
     913  return loadparammacros(defaultmacros,thisfilename);
     914}
     915
     916// loads a collection specific macro file
     917// returns 0 if didn't need to load the file (it was already loaded)
     918//         1 if was (re)loaded
     919//        -1 an error occurred while trying to load the file
     920int displayclass::loadcollectionmacros (text_t thisfilename)
     921{
     922  return loadparammacros(collectionmacros,thisfilename);
     923}
     924
     925
    908926void displayclass::unloaddefaultmacros () {
    909927  defaultmacros->clear();
     928}
     929
     930void displayclass::unloadcollectionmacros () {
     931  collectionmacros->clear();
    910932}
    911933
     
    977999//        -4 if no macroname was supplied
    9781000int displayclass::setmacro (const text_t &macroname,
    979                text_t package,
    980                const text_t &macrovalue)
     1001                text_t package,
     1002                const text_t &macrovalue)
    9811003{
    9821004  // make sure a macroname was supplied
     
    12161238
    12171239
     1240// setparammacro adds an entry to the list of default macros
     1241// returns 0 if there was no error,
     1242//        -1 if it redefined a macro
     1243//        -2 if it hid a Global macro
     1244//        -3 if it redefined a macro and hid a Global macro
     1245//        -4 if no macroname was supplied
     1246int displayclass::setparammacro (parammacros_t* macrotable,
     1247                 text_t package, const text_t &macroname,
     1248                 text_t params, const text_t &filename,
     1249                 const text_t &macrovalue)
     1250{
     1251  // make sure a macroname was supplied
     1252  if (macroname.empty()) return -4;
     1253
     1254  // put the parameters in a standard form
     1255  paramhashtype paramhash;
     1256  if (params.empty()) params = "ignore=yes";
     1257  splitparams (params, paramhash);
     1258  joinparams (paramhash, params);
     1259
     1260  // make package "Global" if it doesn't point to anything yet
     1261  if (package.empty()) package = "Global";
     1262
     1263  // remember these parameters
     1264  allparams.insert (params);
     1265
     1266  // remember this filename (this part isn't finished yet -- Rodger).
     1267
     1268  // set the macro
     1269  return macrotable->setmacro(package, macroname, params, filename, macrovalue);
     1270}
     1271
    12181272// setdefaultmacro adds an entry to the list of default macros
    12191273// returns 0 if there was no error,
     
    12231277//        -4 if no macroname was supplied
    12241278int displayclass::setdefaultmacro (text_t package, const text_t &macroname,
    1225                   text_t params, const text_t &filename,
    1226                   const text_t &macrovalue)
    1227 {
    1228   // make sure a macroname was supplied
    1229   if (macroname.empty()) return -4;
    1230 
    1231   // put the parameters in a standard form
    1232   paramhashtype paramhash;
    1233   if (params.empty()) params = "ignore=yes";
    1234   splitparams (params, paramhash);
    1235   joinparams (paramhash, params);
    1236 
    1237   // make package "Global" if it doesn't point to anything yet
    1238   if (package.empty()) package = "Global";
    1239 
    1240   // remember these parameters
    1241   allparams.insert (params);
    1242 
    1243   // remember this filename (this part isn't finished yet -- Rodger).
    1244 
    1245   // set the macro
    1246   return defaultmacros->setmacro(package, macroname, params, filename, macrovalue);
     1279                   text_t params, const text_t &filename,
     1280                   const text_t &macrovalue)
     1281{
     1282  return setparammacro(defaultmacros,package,macroname,params,filename,macrovalue);
     1283}
     1284
     1285
     1286// setcollectionmacro adds an entry to the list of collection specific macros
     1287// returns 0 if there was no error,
     1288//        -1 if it redefined a macro
     1289//        -2 if it hid a Global macro
     1290//        -3 if it redefined a macro and hid a Global macro
     1291//        -4 if no macroname was supplied
     1292int displayclass::setcollectionmacro (text_t package, const text_t &macroname,
     1293                      text_t params, const text_t &filename,
     1294                      const text_t &macrovalue)
     1295{
     1296  return setparammacro(collectionmacros,package,macroname,params,filename,macrovalue);
    12471297}
    12481298
     
    13261376
    13271377  return result;
     1378}
     1379
     1380
     1381mvalue* displayclass::macro_find (parammacros_t* macrotable, text_t packagename,
     1382                  const text_t &macroname)
     1383{
     1384  mvalue *macrovalue = NULL;
     1385
     1386  // next look in the named parammacros for the named package
     1387  if (macrotable->macro_find (packagename, macroname) != NULL)
     1388    {
     1389      paramspeclist::iterator paramhere, paramend;
     1390
     1391      paramhere = orderparamlist->begin(); paramend = orderparamlist->end();
     1392      while ((macrovalue == NULL) && (paramhere != paramend))
     1393    {
     1394      macrovalue = macrotable->parameter_find(packagename, macroname,
     1395                          (*paramhere).param);
     1396      paramhere++;
     1397    }
     1398    }
     1399
     1400  return macrovalue;
    13281401}
    13291402
     
    14621535  packagelist.push_back ("Global");
    14631536
    1464   paramspeclist::iterator paramhere, paramend;
    14651537  text_tlist::iterator packagehere = packagelist.begin();
    14661538  text_tlist::iterator packageend = packagelist.end();
     
    14731545    macrovalue = currentmacros->macro_find("Style", macroname);
    14741546
     1547      // look in the collection specific macros
     1548      if (macrovalue == NULL) {
     1549    macrovalue = macro_find(collectionmacros,*packagehere,macroname);
     1550      }
     1551
     1552      // and again in the collection specific package "Style"
     1553      if (macrovalue == NULL) {
     1554    macrovalue = macro_find(collectionmacros,(char*)"Style",macroname);
     1555      }
     1556
    14751557      // look in the default macros
    1476       if (macrovalue == NULL)
    1477     {
    1478       // next look in the defaultmacros
    1479       if (defaultmacros->macro_find (*packagehere, macroname) != NULL)
    1480         {
    1481           paramhere = orderparamlist->begin(); paramend = orderparamlist->end();
    1482           while ((macrovalue == NULL) && (paramhere != paramend))
    1483         {
    1484 //        cerr << text_t2ascii << "\npackage: " << *packagehere << "\n";
    1485 //        cerr << text_t2ascii << "macroname: " << macroname << "\n";
    1486 //        cerr << text_t2ascii << "param: " << (*paramhere).param << "\n";
    1487 //        cerr << "spec: " << (int)((*paramhere).spec) << "\n";
    1488           macrovalue = defaultmacros->parameter_find(*packagehere, macroname,
    1489                                  (*paramhere).param);
    1490           paramhere++;
    1491         }
    1492         }
    1493     }
     1558      if (macrovalue == NULL) {
     1559    macrovalue = macro_find(defaultmacros,*packagehere,macroname);
     1560      }
    14941561
    14951562      // and again in the package "Style"
    1496       if (macrovalue == NULL)
    1497     {
    1498       // next look in the defaultmacros
    1499       if (defaultmacros->macro_find ("Style", macroname) != NULL)
    1500         {
    1501           paramhere = orderparamlist->begin(); paramend = orderparamlist->end();
    1502           while ((macrovalue == NULL) && (paramhere != paramend))
    1503         {
    1504           macrovalue = defaultmacros->parameter_find("Style", macroname,
    1505                                  (*paramhere).param);
    1506           paramhere++;
    1507         }
    1508         }
    1509     }
     1563      if (macrovalue == NULL) {
     1564    macrovalue = macro_find(defaultmacros,(char*)"Style",macroname);
     1565      }
     1566
    15101567      if (macrovalue == NULL) packagehere++;
    15111568    }
  • trunk/gsdl/lib/display.h

    r6021 r7386  
    8787
    8888// class prototypes
    89 class defaultmacros_t;
     89class parammacros_t;
    9090class currentmacros_t;
    9191
     
    9696{
    9797  int otherinfo;
     98};
     99
     100// macro value structure
     101struct mvalue
     102{
     103  text_t filename;
     104  text_t value;
    98105};
    99106
     
    186193  int loaddefaultmacros (text_t thisfilename);
    187194
     195  // loads a collection specific macro file
     196  // returns 0 if didn't need to load the file (it was already loaded)
     197  //         1 if was (re)loaded
     198  //        -1 an error occurred while trying to load the file
     199  int loadcollectionmacros (text_t thisfilename);
     200
    188201  // unloads all default macros
    189202  void unloaddefaultmacros ();
     203
     204  // unloads all collection specific macros
     205  void unloadcollectionmacros ();
    190206 
    191207  // prepares to create a page: deletes all macros set with
     
    230246
    231247  // general variables
    232   text_tset allparams;  // possible parameter combinations
    233   defaultmacros_t *defaultmacros;
    234   fileinfomap *defaultfiles;
     248  text_tset        allparams;  // possible parameter combinations
     249  parammacros_t *defaultmacros;
     250  parammacros_t *collectionmacros;
     251  fileinfomap     *defaultfiles;
    235252 
    236253  // variables to do with a page expansion
     
    248265  int checkdefaultmacrofiles ();
    249266
     267  int loadparammacros (parammacros_t* macrotable, text_t thisfilename);
     268
     269  int setparammacro (parammacros_t* macrotable,
     270             text_t package, const text_t &macroname,
     271             text_t params, const text_t &filename,
     272             const text_t &macrovalue);
     273
    250274  int setdefaultmacro (text_t package, const text_t &macroname,
    251275               text_t params, const text_t &filename,
    252276               const text_t &macrovalue);
    253277
     278  int setcollectionmacro (text_t package, const text_t &macroname,
     279              text_t params, const text_t &filename,
     280              const text_t &macrovalue);
     281
    254282  // evaluates a boolean expression
    255283  bool boolexpr (text_t package, const text_t &expr, int recursiondepth);
     284
     285  mvalue* macro_find (parammacros_t* macrotable, text_t packagename,
     286              const text_t &macroname);
    256287
    257288  // (recursively) expand out a macro
Note: See TracChangeset for help on using the changeset viewer.