"Fossies" - the Fresh Open Source Software Archive

Member "OpenSP-1.5.2/include/Dtd.h" (5 Nov 2005, 11625 Bytes) of package /linux/misc/old/OpenSP-1.5.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Dtd.h" see the Fossies "Dox" file reference documentation.

    1 // Copyright (c) 1994 James Clark
    2 // See the file COPYING for copying permission.
    3 
    4 #ifndef Dtd_INCLUDED
    5 #define Dtd_INCLUDED 1
    6 #ifdef __GNUG__
    7 #pragma interface
    8 #endif
    9 
   10 #include "NamedTable.h"
   11 #include "NamedResourceTable.h"
   12 #include "ElementType.h"
   13 #include "Notation.h"
   14 #include "Entity.h"
   15 #include "ShortReferenceMap.h"
   16 #include "Resource.h"
   17 #include "StringC.h"
   18 #include "StringResource.h"
   19 #include "Boolean.h"
   20 #include "Vector.h"
   21 #include "HashTable.h"
   22 
   23 #ifdef SP_NAMESPACE
   24 namespace SP_NAMESPACE {
   25 #endif
   26 
   27 class Syntax;
   28 class ParserState;
   29 
   30 class SP_API Dtd : public Resource {
   31 public:
   32   typedef NamedTableIter<ElementType> ElementTypeIter;
   33   typedef ConstNamedTableIter<ElementType> ConstElementTypeIter;
   34   typedef NamedTableIter<RankStem> RankStemIter;
   35   typedef ConstNamedTableIter<RankStem> ConstRankStemIter;
   36   typedef NamedTableIter<ShortReferenceMap> ShortReferenceMapIter;
   37   typedef ConstNamedResourceTableIter<Notation> ConstNotationIter;
   38   typedef NamedResourceTableIter<Notation> NotationIter;
   39   typedef ConstNamedResourceTableIter<Entity> ConstEntityIter;
   40   typedef NamedResourceTableIter<Entity> EntityIter;
   41   Dtd(const StringC &name, Boolean isBase);
   42   ~Dtd();
   43   ConstPtr<Entity> lookupEntity(Boolean isParameter, const StringC &) const;
   44   const Entity *lookupEntityTemp(Boolean isParameter, const StringC &) const;
   45   Ptr<Entity> lookupEntity(Boolean isParameter, const StringC &);
   46   Ptr<Entity> insertEntity(const Ptr<Entity> &, Boolean replace = 0);
   47   Ptr<Entity> removeEntity(Boolean isParameter, const StringC &);
   48   ConstEntityIter generalEntityIter() const;
   49   EntityIter generalEntityIter();
   50   ConstEntityIter parameterEntityIter() const;
   51   EntityIter parameterEntityIter();
   52 
   53   ConstPtr<Entity> defaultEntity() const;
   54   const Entity *defaultEntityTemp() const;
   55   void setDefaultEntity(const Ptr<Entity> &, ParserState &);
   56   const ConstPtr<StringResource<Char> > &namePointer() const;
   57   const StringC &name() const;
   58 
   59   const ElementType *lookupElementType(const StringC &) const;
   60   ElementType *lookupElementType(const StringC &);
   61   ElementType *removeElementType(const StringC &);
   62   ElementType *insertElementType(ElementType *);
   63   size_t nElementTypeIndex() const;
   64   size_t allocElementTypeIndex();
   65   ConstElementTypeIter elementTypeIter() const;
   66   ElementTypeIter elementTypeIter();
   67 
   68   const RankStem *lookupRankStem(const StringC &) const;
   69   RankStem *lookupRankStem(const StringC &);
   70   RankStem *insertRankStem(RankStem *);
   71   size_t nRankStem() const;
   72   ConstRankStemIter rankStemIter() const;
   73   RankStemIter rankStemIter();
   74 
   75   const ShortReferenceMap *lookupShortReferenceMap(const StringC &) const;
   76   ShortReferenceMap *lookupShortReferenceMap(const StringC &);
   77   ShortReferenceMap *insertShortReferenceMap(ShortReferenceMap *);
   78   ShortReferenceMapIter shortReferenceMapIter();
   79 
   80   Boolean shortrefIndex(const StringC &, const Syntax &, size_t &index);
   81   size_t nShortref() const;
   82   const StringC &shortref(size_t i) const;
   83   void addNeededShortref(const StringC &);
   84 
   85   ConstPtr<Notation> lookupNotation(const StringC &) const;
   86   const Notation *lookupNotationTemp(const StringC &) const;
   87   Ptr<Notation> lookupNotation(const StringC &);
   88   Ptr<Notation> insertNotation(const Ptr<Notation> &);
   89   Ptr<Notation> removeNotation(const StringC &);
   90   ConstNotationIter notationIter() const;
   91   NotationIter notationIter();
   92 
   93   size_t allocCurrentAttributeIndex();
   94   size_t nCurrentAttribute() const;
   95   size_t allocElementDefinitionIndex();
   96   size_t nElementDefinition() const;
   97   size_t allocAttributeDefinitionListIndex();
   98   size_t nAttributeDefinitionList() const;
   99   const ElementType *documentElementType() const;
  100   Boolean isBase() const;
  101   Boolean isInstantiated() const;
  102   void instantiate();
  103 
  104   Ptr<AttributeDefinitionList> &implicitElementAttributeDef();
  105   void setImplicitElementAttributeDef(const Ptr<AttributeDefinitionList> &);
  106   Ptr<AttributeDefinitionList> &implicitNotationAttributeDef();
  107   void setImplicitNotationAttributeDef(const Ptr<AttributeDefinitionList> &);
  108 private:
  109   Dtd(const Dtd &);     // undefined
  110   void operator=(const Dtd &);  // undefined
  111   NamedResourceTable<Entity> generalEntityTable_;
  112   NamedResourceTable<Entity> parameterEntityTable_;
  113   ConstPtr<Entity> defaultEntity_;
  114   ConstPtr<StringResource<Char> > name_;
  115   NamedTable<ElementType> elementTypeTable_;
  116   NamedTable<RankStem> rankStemTable_;
  117   NamedTable<ShortReferenceMap> shortReferenceMapTable_;
  118   NamedResourceTable<Notation> notationTable_;
  119   size_t nCurrentAttribute_;
  120   size_t nElementDefinition_;
  121   size_t nAttributeDefinitionList_;
  122   size_t nElementType_;
  123   ElementType *documentElementType_;
  124   Vector<StringC> shortrefs_;
  125   HashTable<StringC,int> shortrefTable_;
  126   Boolean isBase_;
  127   Boolean isInstantitated_;
  128   Ptr<AttributeDefinitionList> implicitElementAttributeDef_;
  129   Ptr<AttributeDefinitionList> implicitNotationAttributeDef_;
  130 };
  131 
  132 inline
  133 ConstPtr<Entity> Dtd::lookupEntity(Boolean isParameter, const StringC &name)
  134   const
  135 {
  136   return (isParameter
  137       ? &parameterEntityTable_
  138       : &generalEntityTable_)->lookupConst(name);
  139 }
  140 
  141 inline
  142 const Entity *Dtd::lookupEntityTemp(Boolean isParameter, const StringC &name)
  143   const
  144 {
  145   return (isParameter
  146       ? &parameterEntityTable_
  147       : &generalEntityTable_)->lookupTemp(name);
  148 }
  149 
  150 inline
  151 Ptr<Entity> Dtd::lookupEntity(Boolean isParameter, const StringC &name)
  152 {
  153   return (isParameter
  154       ? &parameterEntityTable_
  155       : &generalEntityTable_)->lookup(name);
  156 }
  157 
  158 inline
  159 Ptr<Entity>
  160 Dtd::insertEntity(const Ptr<Entity> &entity, Boolean replace)
  161 {
  162   return ((entity->declType() == Entity::parameterEntity 
  163        || entity->declType() == Entity::doctype)
  164       ? &parameterEntityTable_
  165       : &generalEntityTable_)->insert(entity, replace);
  166 }
  167 
  168 inline
  169 Ptr<Entity> Dtd::removeEntity(Boolean isParameter, const StringC &name)
  170 {
  171   return (isParameter
  172       ? &parameterEntityTable_
  173       : &generalEntityTable_)->remove(name);
  174 }
  175 
  176 inline
  177 Dtd::ConstEntityIter Dtd::generalEntityIter() const
  178 {
  179   // Avoid use of typedef to work around MSVC 2.0 bug.
  180   return ConstNamedResourceTableIter<Entity>(generalEntityTable_);
  181 }
  182 
  183 inline
  184 Dtd::EntityIter Dtd::generalEntityIter()
  185 {
  186   // Avoid use of typedef to work around MSVC 2.0 bug.
  187   return NamedResourceTableIter<Entity>(generalEntityTable_);
  188 }
  189 
  190 inline
  191 Dtd::ConstEntityIter Dtd::parameterEntityIter() const
  192 {
  193   // Avoid use of typedef to work around MSVC 2.0 bug.
  194   return ConstNamedResourceTableIter<Entity>(parameterEntityTable_);
  195 }
  196 
  197 inline
  198 Dtd::EntityIter Dtd::parameterEntityIter()
  199 {
  200   // Avoid use of typedef to work around MSVC 2.0 bug.
  201   return NamedResourceTableIter<Entity>(parameterEntityTable_);
  202 }
  203 
  204 inline
  205 ConstPtr<Entity> Dtd::defaultEntity() const
  206 {
  207   return defaultEntity_;
  208 }
  209 
  210 inline
  211 const Entity *Dtd::defaultEntityTemp() const
  212 {
  213   return defaultEntity_.pointer();
  214 }
  215 
  216 inline
  217 const ConstPtr<StringResource<Char> > &Dtd::namePointer() const
  218 {
  219   return name_;
  220 }
  221 
  222 inline
  223 const StringC &Dtd::name() const
  224 {
  225   return *name_;
  226 }
  227 
  228 inline
  229 size_t Dtd::allocCurrentAttributeIndex()
  230 {
  231   return nCurrentAttribute_++;
  232 }
  233 
  234 inline
  235 size_t Dtd::nCurrentAttribute() const
  236 {
  237   return nCurrentAttribute_;
  238 }
  239 
  240 inline
  241 size_t Dtd::allocElementDefinitionIndex()
  242 {
  243   return nElementDefinition_++;
  244 }
  245 
  246 inline
  247 size_t Dtd::nElementDefinition() const
  248 {
  249   return nElementDefinition_;
  250 }
  251 
  252 inline
  253 size_t Dtd::allocAttributeDefinitionListIndex()
  254 {
  255   return nAttributeDefinitionList_++;
  256 }
  257 
  258 inline
  259 size_t Dtd::nAttributeDefinitionList() const
  260 {
  261   return nAttributeDefinitionList_;
  262 }
  263 
  264 inline
  265 const ElementType *Dtd::lookupElementType(const StringC &name) const
  266 {
  267   return elementTypeTable_.lookup(name);
  268 }
  269 
  270 inline
  271 ElementType *Dtd::lookupElementType(const StringC &name)
  272 {
  273   return elementTypeTable_.lookup(name);
  274 }
  275 
  276 inline
  277 ElementType *Dtd::insertElementType(ElementType *e)
  278 {
  279   return elementTypeTable_.insert(e);
  280 }
  281 
  282 inline
  283 Dtd::ElementTypeIter Dtd::elementTypeIter()
  284 {
  285   // Avoid use of typedef to work around MSVC 2.0 bug.
  286   return NamedTableIter<ElementType>(elementTypeTable_);
  287 }
  288 
  289 inline
  290 Dtd::ConstElementTypeIter Dtd::elementTypeIter() const
  291 {
  292   // Avoid use of typedef to work around MSVC 2.0 bug.
  293   return ConstNamedTableIter<ElementType>(elementTypeTable_);
  294 }
  295 
  296 inline
  297 Dtd::RankStemIter Dtd::rankStemIter()
  298 {
  299   // Avoid use of typedef to work around MSVC 2.0 bug.
  300   return NamedTableIter<RankStem>(rankStemTable_);
  301 }
  302 
  303 inline
  304 Dtd::ConstRankStemIter Dtd::rankStemIter() const
  305 {
  306   // Avoid use of typedef to work around MSVC 2.0 bug.
  307   return ConstNamedTableIter<RankStem>(rankStemTable_);
  308 }
  309 
  310 inline
  311 ElementType *Dtd::removeElementType(const StringC &name)
  312 {
  313   return elementTypeTable_.remove(name);
  314 }
  315 
  316 inline
  317 size_t Dtd::nElementTypeIndex() const
  318 {
  319   // index 0 is reserved for #pcdata
  320   return 1 + nElementType_;
  321 }
  322 
  323 inline
  324 size_t Dtd::allocElementTypeIndex()
  325 {
  326   return 1 + nElementType_++;
  327 }
  328 
  329 inline
  330 const RankStem *Dtd::lookupRankStem(const StringC &name) const
  331 {
  332   return rankStemTable_.lookup(name);
  333 }
  334 
  335 inline
  336 RankStem *Dtd::lookupRankStem(const StringC &name)
  337 {
  338   return rankStemTable_.lookup(name);
  339 }
  340 
  341 inline
  342 RankStem *Dtd::insertRankStem(RankStem *e)
  343 {
  344   return rankStemTable_.insert(e);
  345 }
  346 
  347 inline
  348 size_t Dtd::nRankStem() const
  349 {
  350   return rankStemTable_.count();
  351 }
  352 
  353 inline
  354 ConstPtr<Notation> Dtd::lookupNotation(const StringC &name) const
  355 {
  356   return notationTable_.lookupConst(name);
  357 }
  358 
  359 inline
  360 const Notation *Dtd::lookupNotationTemp(const StringC &name) const
  361 {
  362   return notationTable_.lookupTemp(name);
  363 }
  364 
  365 inline
  366 Ptr<Notation> Dtd::lookupNotation(const StringC &name)
  367 {
  368   return notationTable_.lookup(name);
  369 }
  370 
  371 inline
  372 Ptr<Notation> Dtd::insertNotation(const Ptr<Notation> &nt)
  373 {
  374   return notationTable_.insert(nt);
  375 }
  376 
  377 inline
  378 Dtd::ConstNotationIter Dtd::notationIter() const
  379 {
  380   // Avoid use of typedef to work around MSVC 2.0 bug.
  381   return ConstNamedResourceTableIter<Notation>(notationTable_);
  382 }
  383 
  384 inline
  385 Dtd::NotationIter Dtd::notationIter()
  386 {
  387   // Avoid use of typedef to work around MSVC 2.0 bug.
  388   return NamedResourceTableIter<Notation>(notationTable_);
  389 }
  390 
  391 inline
  392 Ptr<Notation> Dtd::removeNotation(const StringC &name)
  393 {
  394   return notationTable_.remove(name);
  395 }
  396 
  397 inline
  398 const ElementType *Dtd::documentElementType() const
  399 {
  400   return documentElementType_;
  401 }
  402 
  403 inline
  404 const ShortReferenceMap *Dtd::lookupShortReferenceMap(const StringC &name) const
  405 {
  406   return shortReferenceMapTable_.lookup(name);
  407 }
  408 
  409 inline
  410 ShortReferenceMap *Dtd::lookupShortReferenceMap(const StringC &name)
  411 {
  412   return shortReferenceMapTable_.lookup(name);
  413 }
  414 
  415 inline
  416 ShortReferenceMap *Dtd::insertShortReferenceMap(ShortReferenceMap *map)
  417 {
  418   return shortReferenceMapTable_.insert(map);
  419 }
  420 
  421 inline
  422 Dtd::ShortReferenceMapIter Dtd::shortReferenceMapIter()
  423 {
  424   // Avoid use of typedef to work around MSVC 2.0 bug.
  425   return NamedTableIter<ShortReferenceMap>(shortReferenceMapTable_);
  426 }
  427 
  428 inline
  429 Boolean Dtd::isBase() const
  430 {
  431   return isBase_;
  432 }
  433 
  434 inline
  435 size_t Dtd::nShortref() const
  436 {
  437   return shortrefs_.size();
  438 }
  439 
  440 inline
  441 const StringC &Dtd::shortref(size_t i) const
  442 {
  443   return shortrefs_[i];
  444 }
  445 
  446 inline
  447 Ptr<AttributeDefinitionList> &Dtd::implicitElementAttributeDef()
  448 {
  449   return implicitElementAttributeDef_;
  450 }
  451 
  452 inline
  453 void Dtd::setImplicitElementAttributeDef(const Ptr<AttributeDefinitionList> &def)
  454 {
  455   implicitElementAttributeDef_ = def;
  456 }
  457 
  458 inline
  459 Ptr<AttributeDefinitionList> &Dtd::implicitNotationAttributeDef()
  460 {
  461   return implicitNotationAttributeDef_;
  462 }
  463 
  464 inline
  465 void Dtd::setImplicitNotationAttributeDef(const Ptr<AttributeDefinitionList> &def)
  466 {
  467   implicitNotationAttributeDef_ = def;
  468 }
  469 
  470 inline 
  471 Boolean Dtd::isInstantiated() const
  472 {
  473   return isInstantitated_;
  474 }
  475 
  476 inline 
  477 void Dtd::instantiate() 
  478 {
  479   isInstantitated_ = 1;
  480 }
  481 
  482 #ifdef SP_NAMESPACE
  483 }
  484 #endif
  485 
  486 #endif /* not Dtd_INCLUDED */