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

container.cc

00001 /*
00002 *  Name:      container.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *             Angel Jimenez Jimenez
00005 *  Summary:   HTML container
00006 *  Date:      $Date: 2003/04/14 00:18:35 $
00007 *  Revision:  $Revision: 1.1 $
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 #include <mpcl/text/html/container.hh>
00028 
00029 
00030 //
00031 //  C O N S T R U C T O R S
00032 //
00033 
00034 mpcl::text::html::QTTag mpcl::text::html::TContainer::
00035 findOrInsertTag (const TString& rkyIDENTIFIER)
00036 {
00037 
00038   QTTag                       qtTag;
00039   std::size_t                 zOffset;
00040   TStringToTagMap::iterator   I = tStringToTagMap.begin();
00041 
00042   zOffset = rkyIDENTIFIER.find (kcIdentifierSeparator);
00043   if ( TString::npos == zOffset )
00044   {
00045     //
00046     //  There is no separator.
00047     //
00048     I = tStringToTagMap.find (rkyIDENTIFIER);
00049     if ( I != tStringToTagMap.end() )
00050     {
00051       qtTag = I->second;
00052     }
00053     else
00054     {
00055       if ( isDynamiclyLoadable() )
00056       {
00057         qtTag = new TTag (rkyIDENTIFIER.c_str(), true);
00058         insert (qtTag);
00059       }
00060     }
00061   }
00062   else
00063   {
00064     TString   yFirstIdentifierPart (rkyIDENTIFIER.substr (0, zOffset));
00065     TString   yLastIdentifierPart (rkyIDENTIFIER.substr (zOffset + 1));
00066 
00067     //
00068     //  If an tag with yFirstIdentifierPart as identifier is found, then it is
00069     //  a  container.  So  it  is  called using tag(), with the  rest  of  the
00070     //  identifier as parameter.
00071     //
00072     I = tStringToTagMap.find (yFirstIdentifierPart);
00073     if ( I != tStringToTagMap.end() )
00074     {
00075 // <DELETE id="smart-pointers">
00076 //       QTContainer   qtContainer;
00077       
00078 //       DynamicCast (qtContainer, I->second);
00079 // </DELETE>
00080       TContainer*   ptContainer = I->second.dynamicCast<TContainer*>();
00081 
00082       qtTag = ptContainer->findOrInsertTag (yLastIdentifierPart);
00083     }
00084   }
00085   if ( !qtTag )
00086   {
00087     TString   yMessage = Format ("there is no tag called '%s'", rkyIDENTIFIER.c_str());
00088 
00089     throw TConstraintException (yMessage, __FILE__, __LINE__);
00090   }
00091   return qtTag;
00092   
00093 }  // findOrInsertTag()
00094 
00095 
00096 void mpcl::text::html::TContainer::
00097 insertAs ( const TString& rkyTAG_IDENTIFIER ,
00098            const QTTag&   rkqtTAG           ,
00099            iterator       tINDEX            )
00100 {
00101   
00102   TString   yIdentifier (rkyTAG_IDENTIFIER);
00103 
00104   if ( yIdentifier.empty() )
00105   {
00106     yIdentifier.append (1, '_');
00107     insertAs (yIdentifier, rkqtTAG, tINDEX);
00108   }
00109   else
00110   {
00111     TStringToTagMap::const_iterator   I (tStringToTagMap.find (yIdentifier));
00112     
00113     if ( I == tStringToTagMap.end() )
00114     {
00115       //
00116       //  No tag found with name rkyTAG_IDENTIFIER.
00117       //
00118       tStringToTagMap.bind (yIdentifier, rkqtTAG);
00119       tTagList.insert (tINDEX, rkqtTAG);
00120     }
00121     else
00122     {
00123       //
00124       //  If there is another tag with the same name,
00125       //  then inserts this tag with another name.
00126       //
00127       yIdentifier.append (1, '_');
00128       insertAs (yIdentifier, rkqtTAG, tINDEX);
00129     }
00130   }
00131 
00132 }  // insertAs()
00133 
00134 
00135 void mpcl::text::html::TContainer::
00136 setId (const char* pkcID, bool gDELEGATE)
00137 {
00138 
00139   iterator   I    = tTagList.begin();
00140   iterator   tEnd = tTagList.end();
00141   
00142   TTag::setId (pkcID, gDELEGATE);
00143   if ( gDELEGATE )
00144   {
00145     for (; ( I != tEnd ) ;++I)
00146     {
00147       (*I)->setId (pkcID, gDELEGATE);
00148     }
00149   }
00150 
00151 }  // setId()
00152 
00153 
00154 void mpcl::text::html::TContainer::
00155 setId (const TString& rkyID, bool gDELEGATE)
00156 {
00157 
00158   iterator   I    = tTagList.begin();
00159   iterator   tEnd = tTagList.end();
00160   
00161   TTag::setId (rkyID, gDELEGATE);
00162   if ( gDELEGATE )
00163   {
00164     for (; ( I != tEnd ) ;++I)
00165     {
00166       (*I)->setId (rkyID, gDELEGATE);
00167     }
00168   }
00169 
00170 }  // setId()
00171 
00172 
00173 void mpcl::text::html::TContainer::
00174 setClass (const TString& rkyCLASS, bool gDELEGATE)
00175 {
00176 
00177   iterator   I    = tTagList.begin();
00178   iterator   tEnd = tTagList.end();
00179   
00180   TTag::setClass (rkyCLASS);
00181   if ( gDELEGATE )
00182   {
00183     for (; ( I != tEnd ) ;++I)
00184     {
00185       (*I)->setClass (rkyCLASS, gDELEGATE);
00186     }
00187   }
00188 
00189 }  // setClass()
00190 
00191 
00192 void mpcl::text::html::TContainer::
00193 setClass (const char* pkcCLASS, bool gDELEGATE)
00194 {
00195 
00196   iterator   I    = tTagList.begin();
00197   iterator   tEnd = tTagList.end();
00198   
00199   TTag::setClass (pkcCLASS);
00200   if ( gDELEGATE )
00201   {
00202     for (; ( I != tEnd ) ;++I)
00203     {
00204       (*I)->setClass (pkcCLASS, gDELEGATE);
00205     }
00206   }
00207 
00208 }  // setClass()
00209 
00210 
00211 //
00212 //  S E L E C T O R S
00213 //
00214 
00215 mpcl::text::html::QTTag mpcl::text::html::TContainer::
00216 findTag (const TString& rkyIDENTIFIER) const
00217 {
00218 
00219   TStringToTagMap::iterator   I;
00220   QTTag                       qtTag;
00221   std::size_t                 zOffset;
00222 
00223   zOffset = rkyIDENTIFIER.find (kcIdentifierSeparator);
00224   if ( TString::npos == zOffset )
00225   {
00226     //
00227     //  There is no separator.
00228     //
00229     I = tStringToTagMap.find (rkyIDENTIFIER);
00230     if ( I != tStringToTagMap.end() )
00231     {
00232       qtTag = I->second;
00233     }
00234   }
00235   else
00236   {
00237     TString   yFirstIdentifierPart (rkyIDENTIFIER.substr (0, zOffset));
00238     TString   yLastIdentifierPart (rkyIDENTIFIER.substr (zOffset + 1));
00239 
00240     //
00241     //  If an tag with yFirstIdentifierPart as identifier is found, then it is
00242     //  a  container.  So  it  is called using tag(), with  the  rest  of  the
00243     //  identifier as parameter.
00244     //
00245     I = tStringToTagMap.find (yFirstIdentifierPart);
00246     if ( I != tStringToTagMap.end() )
00247     {
00248 // <DELETE id="smart-pointers">
00249 //       QKTContainer   qktContainer;
00250       
00251 //       DynamicCast (qktContainer, I->second);
00252 // </DELETE>
00253 
00254       const TContainer*   pktContainer = I->second.dynamicCast<const TContainer*>();
00255 
00256       qtTag = pktContainer->findTag (yLastIdentifierPart);
00257     }
00258   }
00259   return qtTag;
00260 
00261 }  // findTag()
00262 
00263 
00264 mpcl::text::html::QTTag mpcl::text::html::TContainer::
00265 tag (const TString& rkyIDENTIFIER) const
00266 {
00267 
00268   QTTag   qtTag (findTag (rkyIDENTIFIER));
00269   
00270   if ( !qtTag )
00271   {
00272     TString   yMessage = Format ("there is no tag called '%s'", rkyIDENTIFIER.c_str());
00273     
00274     throw TConstraintException (yMessage, __FILE__, __LINE__);
00275   }
00276   return qtTag;
00277 
00278 }  // tag()
00279 
00280 
00281 void mpcl::text::html::TContainer::
00282 writeUsing ( std::basic_ostream<char>& rtTARGET_OSTREAM        ,
00283              const TString&            rkyQUALIFIED_IDENTIFIER ) const
00284 {
00285 
00286   if ( isVisible() )
00287   {
00288     TStringToStringMap   tTargetVariableMap;
00289     TString              yNewPathIdentifier;
00290     TString              yPathIdentifier        = rkyQUALIFIED_IDENTIFIER;
00291     TString              yGroupAlignInstruction = "group.";
00292 
00293     //
00294     //  Sets the proper instruction.
00295     //
00296     yGroupAlignInstruction += tAttributeMap ["group-align"];
00297     expand (tTargetVariableMap);
00298     if ( gIsQualified && !qualifiedIdentifier().empty() )
00299     {
00300       if ( !yPathIdentifier.empty() )
00301       {
00302         yPathIdentifier += kcIdentifierSeparator;
00303       }
00304       yPathIdentifier += qualifiedIdentifier();
00305     }
00306     tTargetVariableMap ["qualified-identifier"] = yPathIdentifier;
00307     if ( gIsRootNode )
00308     {
00309       if ( gIsQualified && gForwardIdentifier )
00310       {
00311         yNewPathIdentifier += qualifiedIdentifier();
00312       }
00313     }
00314     else
00315     {
00316       yNewPathIdentifier = rkyQUALIFIED_IDENTIFIER;
00317       if ( gIsQualified && gForwardIdentifier && !qualifiedIdentifier().empty() )
00318       {
00319         if ( !yNewPathIdentifier.empty() )
00320         {
00321           yNewPathIdentifier += kcIdentifierSeparator;
00322         }
00323         yNewPathIdentifier += qualifiedIdentifier();
00324       }
00325     }
00326 
00327     //
00328     //  Outputs container.
00329     //
00330     const_iterator   I     = tTagList.begin();
00331     const_iterator   ktEnd = tTagList.end();
00332 
00333     rtTARGET_OSTREAM << code (tTargetVariableMap ["class-identifier"].c_str(), "head", tTargetVariableMap);
00334     rtTARGET_OSTREAM << code (yGroupAlignInstruction.c_str(),                  "head");
00335     for (; ( I != ktEnd ) ;++I)
00336     {
00337       (*I)->writeUsing (rtTARGET_OSTREAM, yNewPathIdentifier);
00338       rtTARGET_OSTREAM << code (yGroupAlignInstruction.c_str(), "internal");
00339     }
00340     rtTARGET_OSTREAM << code (yGroupAlignInstruction.c_str(),                  "foot");
00341     rtTARGET_OSTREAM << code (tTargetVariableMap ["class-identifier"].c_str(), "foot", tTargetVariableMap);
00342   }
00343 
00344 }  // writeUsing()

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