Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

tag.hh

00001 /*
00002 *  Name:      tag.hh
00003 *  Author:    Angel Jimenez Jimenez
00004 *             Rafael Jesus Alcantara Perez
00005 *  Summary:   HTML base tag
00006 *  Date:      $Date: 2003/08/08 23:30:34 $
00007 *  Revision:  $Revision: 1.2 $
00008 *
00009 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00027 #ifndef _MPCL_TEXT_HTML_TAG__
00028 #define _MPCL_TEXT_HTML_TAG__
00029 
00030 #include <list>
00031 #include <memory>
00032 #include "../../io/output_streamable.hh"
00033 #include "../../memory/smart_pointer.hh"
00034 #include "../../util/collection/string_to_string_map.hh"
00035 #include "../codegen/pattern_based_code_generator.hh"
00036 #include "../string.hh"
00037 #include "defs.hh"
00038 
00039 
00041 namespace mpcl
00042 {
00043 
00045   namespace text
00046   {
00047 
00049     namespace html
00050     {
00051 
00052       using memory::TSmartPointer;
00053       using text::codegen::TPatternBasedCodeGenerator;
00054       using util::collection::TStringToStringMap;
00055 
00057       class TTag;
00058 
00060       typedef
00061         TSmartPointer<TTag>
00062         QTTag;
00063 
00065       typedef
00066         TSmartPointer<const TTag>
00067         QKTTag;
00068 
00089       class TTag : public IOutputStreamable<>
00090       {
00091 
00092         public:
00093 
00095           typedef
00096             std::list<QTTag>
00097             TTagList;
00098 
00100           typedef
00101             TTagList::const_iterator
00102             const_iterator;
00103 
00105           typedef
00106             TTagList::iterator
00107             iterator;
00108 
00110           typedef
00111             TTagList::size_type
00112             size_type;
00113 
00114 
00115         protected:
00116 
00118           static TPatternBasedCodeGenerator*   _ptCodeGenerator;
00119 
00121           bool   gForwardIdentifier;
00122 
00124           bool   gHasBeenDynamiclyCreated;
00125 
00127           bool   gIsDynamiclyLoadable;
00128 
00133           bool   gIsQualified;
00134 
00139           bool   gIsRootNode;
00140 
00142           bool   gIsVisible;
00143 
00145           TStringToStringMap   tAttributeMap;
00146 
00147 
00148         public:
00149 
00150           //
00151           //  L O C A L   F U N C T I O N S
00152           //
00153 
00155           static void _setCodeGenerator (const TPatternBasedCodeGenerator& rktCG);
00156 
00157 
00158         public:
00159 
00160           //
00161           //  C O N S T R U C T O R S
00162           //
00163 
00168           TTag (bool gDYNAMICALLY_CREATED = false);
00169 
00175           TTag (const char* pkcIDENTIFIER, const char* pkcVALUE = "");
00176 
00182           TTag (const char* pkcIDENTIFIER, bool gDYNAMICALLY_CREATED);
00183 
00185           virtual ~TTag (void);
00186 
00188           virtual void clear (void) {}
00189 
00191           virtual void reset (void)
00192           {
00193             //
00194             //  If this is an assignable tag.
00195             //
00196             if ( isAssignable() )
00197             {
00198               tAttributeMap ["value"].erase();
00199             }
00200           }
00201 
00207           virtual void setClass ( const TString& rkyCLASS          ,
00208                                   bool           gDELEGATE = false );
00209 
00215           virtual void setClass ( const char* pkcCLASS          ,
00216                                   bool        gDELEGATE = false );
00217 
00222           void setDynamiclyLoadable (bool gDYNAMICLY_LOADABLE)
00223           {
00224             gIsDynamiclyLoadable = gDYNAMICLY_LOADABLE;
00225           }
00226 
00232           virtual void setId (const char* pkcID, bool = false)
00233           {
00234             attribute ("id") = pkcID;
00235           }
00236 
00242           virtual void setId (const TString& rkyID, bool = false)
00243           {
00244             attribute ("id") = rkyID;
00245           }
00246 
00251           virtual void setValue (const TString& rkyVALUE)
00252           {
00253             setValue (rkyVALUE.c_str());
00254           }
00255 
00260           virtual void setValue (const char* pkcVALUE)
00261           {
00262             if ( !isAssignable() )
00263             {
00264               throw TConstraintException ("instance is not assignable", __FILE__, __LINE__);
00265             }
00266             tAttributeMap ["value"] = pkcVALUE;
00267           }
00268 
00273           void setVisibility (bool gIS_VISIBLE)
00274           {
00275             gIsVisible = gIS_VISIBLE;
00276           }
00277 
00283           virtual void update (void) {}
00284 
00285 
00286         public:
00287 
00288           //
00289           //  S E L E C T O R S
00290           //
00291 
00296           virtual TString& attribute (const char* pkcNAME)
00297           {
00298             return tAttributeMap [pkcNAME];
00299           }
00300 
00305           virtual const TString& attribute (const char* pkcNAME) const
00306           {
00307             return tAttributeMap [pkcNAME];
00308           }
00309 
00310           virtual iterator begin (void);
00311 
00312           virtual const_iterator begin (void) const;
00313 
00314           virtual iterator end (void);
00315 
00316           virtual const_iterator end (void) const;
00317 
00322           TString getClass (void) const
00323           {
00324             return tAttributeMap ["class"];
00325           }
00326 
00331           const TString& getId (void) const
00332           {
00333             return tAttributeMap ["id"];
00334           }
00335 
00337           virtual const TString& getValue (void) const
00338           {
00339             return tAttributeMap ["value"];
00340           }
00341 
00347           virtual bool hasAttribute (const char* pkcNAME) const
00348           {
00349             return ( tAttributeMap.end() != tAttributeMap.find (pkcNAME) );
00350           }
00351 
00353           bool hasBeenDynamiclyCreated (void) const
00354           {
00355             return gHasBeenDynamiclyCreated;
00356           }
00357 
00359           virtual const TString& identifier (void) const
00360           {
00361             return tAttributeMap ["identifier"];
00362           }
00363 
00365           virtual bool isAssignable (void) const
00366           {
00367             return !identifier().empty();
00368           }
00369 
00371           bool isDynamiclyLoadable (void) const
00372           {
00373             return gIsDynamiclyLoadable;
00374           }
00375 
00377           bool isQualified (void) const
00378           {
00379             return gIsQualified;
00380           }
00381 
00386           virtual bool isVisible (void) const
00387           {
00388             return gIsVisible;
00389           }
00390 
00391           virtual bool operator == (const TTag& rktTAG) const
00392           {
00393             return ( identifier() == rktTAG.identifier() );
00394           }
00395 
00402           virtual QTTag tag (const TString& rkyIDENTIFIER) const;
00403 
00409           virtual TString& operator () (const char* pkcNAME)
00410           {
00411             return attribute (pkcNAME);
00412           }
00413 
00419           virtual const TString& operator () (const char* pkcNAME) const
00420           {
00421             return attribute (pkcNAME);
00422           }
00423 
00434           virtual const TTag& operator [] (const char* pkcIDENTIFIER) const;
00435 
00437           virtual const TTag& operator [] (const TString& rkyIDENTIFIER) const
00438           {
00439             return operator [] (rkyIDENTIFIER.c_str());
00440           }
00441 
00452           virtual TTag& operator [] (const char* pkcIDENTIFIER);
00453 
00455           virtual TTag& operator [] (const TString& rkyIDENTIFIER)
00456           {
00457             return operator [] (rkyIDENTIFIER.c_str());
00458           }
00459 
00461           virtual const TString& qualifiedIdentifier (void) const
00462           {
00463             return tAttributeMap ["qualified-identifier"];
00464           }
00465 
00474           virtual size_type size (void) const;
00475 
00476           void write (std::basic_ostream<char>& rtOUTPUT_OSTREAM) const
00477           {
00478             writeUsing (rtOUTPUT_OSTREAM, "");
00479           }
00480 
00488           virtual void writeUsing ( std::basic_ostream<char>& rtTARGET_OSTREAM        ,
00489                                     const TString&            rkyQUALIFIED_IDENTIFIER ) const;
00490 
00491 
00492         protected:
00493 
00494           //
00495           //  S E L E C T O R S
00496           //
00497 
00498           TString code (const char* pkcINSTRUCTION, const char* pkcCLAUSE) const;
00499 
00500           TString code ( const char*               pkcINSTRUCTION ,
00501                          const char*               pkcCLAUSE      ,
00502                          const TStringToStringMap& rktVALUE_MAP   ) const;
00503 
00504           void expand (TStringToStringMap& rtTARGET_VALUE_MAP) const;
00505 
00506       };  // class TTag
00507 
00508     }  // namespace html
00509 
00510   }  // namespace text
00511 
00512 }  // namespace mpcl
00513 
00514 
00515 #endif  // not _MPCL_TEXT_HTML_TAG__

Generated on Mon Oct 13 02:35:24 2003 for MPCL by doxygen1.2.18