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

layout_table.cc

00001 /*
00002 *  Name:      layout_table.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   HTML table
00005 *  Date:      $Date: 2003/04/14 00:18:35 $
00006 *  Revision:  $Revision: 1.1 $
00007 *
00008 *  Copyright (C) 1994-2002  Rafael Jesus Alcantara Perez <rafa@dedalo-ing.com>
00009 *
00010 *  This program is free software; you can redistribute it and/or modify
00011 *  it under the terms of the GNU General Public License as published by
00012 *  the Free Software Foundation; either version 2 of the License, or
00013 *  (at your option) any later version.
00014 *
00015 *  This program is distributed in the hope that it will be useful,
00016 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 *  GNU General Public License for more details.
00019 *
00020 *  You should have received a copy of the GNU General Public License
00021 *  along with this program; if not, write to the Free Software
00022 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00023 *  MA 02111-1307, USA.
00024 */
00025 
00026 #include <algorithm>
00027 #include <mpcl/text/html/layout_table.hh>
00028 #include <mpcl/text/html/table_cell.hh>
00029 #include <mpcl/text/html/table_row.hh>
00030 
00031 
00032 //
00033 //  S E L E C T O R S
00034 //
00035 
00036 mpcl::text::html::QTTag mpcl::text::html::TLayoutTable::
00037 findTag (const TString& rkyIDENTIFIER) const
00038 {
00039 
00040   TStringToTagMap::const_iterator   I;
00041   TStringToTagMap::const_iterator   J;
00042   TStringToTagMap::const_iterator   K;
00043   bool                                  gHasMoreIdentifiers;
00044 // <DELETE id="smart-pointers">
00045 //   QKTTableCell                      qktCell;
00046 //   QKTContainer                      qktContainer;
00047 //   QKTTableRow                       qktRow;
00048 // </DELETE>
00049   const TTableCell*                 pktCell;
00050   const TContainer*                 pktContainer;
00051   const TTableRow*                  pktRow;
00052   QTTag                             qtTag;
00053   TString                               yFirstIdentifierPart;
00054   TString                               yLastIdentifierPart;
00055   std::size_t                           zOffset;
00056 
00057   zOffset             = rkyIDENTIFIER.find (kcIdentifierSeparator);
00058   gHasMoreIdentifiers = ( TString::npos != zOffset );
00059   if ( !gHasMoreIdentifiers )
00060   {
00061     yFirstIdentifierPart = rkyIDENTIFIER;
00062   }
00063   else
00064   {
00065     yFirstIdentifierPart = rkyIDENTIFIER.substr (0, zOffset);
00066     yLastIdentifierPart  = rkyIDENTIFIER.substr (zOffset + 1);
00067   }
00068 
00069   //
00070   //  Searches in for the item into every cell contained in this row.
00071   //
00072   I = tStringToTagMap.begin();
00073   for (; ( I != tStringToTagMap.end() && !qtTag ) ;++I)
00074   {
00075     //
00076     //  Searches all rows.
00077     //
00078 // <DELETE id="smart-pointers">
00079 //     DynamicCast (qktRow, I->second);
00080 //     J = qktRow->tStringToTagMap.begin();
00081 //     for (; ( ( J != qktRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00082 // </DELETE>
00083     pktRow = I->second.dynamicCast<const TTableRow*>();
00084     J      = pktRow->tStringToTagMap.begin();
00085     for (; ( ( J != pktRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00086     {
00087       //
00088       //  Searches for all items in all cells per row.
00089       //
00090 // <DELETE id="smart-pointers">
00091 //       DynamicCast (qktCell, J->second);
00092 //       K = qktCell->tStringToTagMap.find (yFirstIdentifierPart);
00093 //       if ( K != qktCell->tStringToTagMap.end() )
00094 // </DELETE>
00095       pktCell = J->second.dynamicCast<const TTableCell*>();
00096       K       = pktCell->tStringToTagMap.find (yFirstIdentifierPart);
00097       if ( K != pktCell->tStringToTagMap.end() )
00098       {
00099         if ( !gHasMoreIdentifiers )
00100         {
00101           qtTag = K->second;
00102         }
00103         else
00104         {
00105 // <DELETE id="smart-pointers">
00106 //           DynamicCast (qktContainer, K->second);
00107 //           qtTag = qktContainer->findTag (yLastIdentifierPart);
00108 // </DELETE>
00109           pktContainer = K->second.dynamicCast<const TContainer*>();
00110           qtTag        = pktContainer->findTag (yLastIdentifierPart);
00111         }
00112         break;
00113       }
00114     }
00115   }
00116   return qtTag;
00117 
00118 }  // findTag()
00119 
00120 
00121 mpcl::text::html::QTTag mpcl::text::html::TLayoutTable::
00122 findOrInsertTag (const TString& rkyIDENTIFIER)
00123 {
00124 
00125   TStringToTagMap::iterator   I;
00126   TStringToTagMap::iterator   J;
00127   TStringToTagMap::iterator   K;
00128   bool                            gHasMoreIdentifiers;
00129 // <DELETE id="smart-pointers">
00130 //   QTTableCell                 qtCell;
00131 //   QTContainer                 qtContainer;
00132 //   QTTableRow                  qtRow;
00133 // </DELETE>
00134   TTableCell*                 ptCell;
00135   TContainer*                 ptContainer;
00136   TTableRow*                  ptRow;
00137   QTTag                       qtTag;
00138   TString                         yFirstIdentifierPart;
00139   TString                         yLastIdentifierPart;
00140   std::size_t                     zOffset;
00141 
00142   zOffset             = rkyIDENTIFIER.find (kcIdentifierSeparator);
00143   gHasMoreIdentifiers = ( TString::npos != zOffset );
00144   if ( !gHasMoreIdentifiers )
00145   {
00146     yFirstIdentifierPart = rkyIDENTIFIER;
00147   }
00148   else
00149   {
00150     yFirstIdentifierPart = rkyIDENTIFIER.substr (0, zOffset);
00151     yLastIdentifierPart  = rkyIDENTIFIER.substr (zOffset + 1);
00152   }
00153 
00154   //
00155   //  Searches in for the item into every cell contained in this row.
00156   //
00157   I = tStringToTagMap.begin();
00158   for (; ( I != tStringToTagMap.end() && !qtTag ) ;++I)
00159   {
00160     //
00161     //  Searches all rows.
00162     //
00163 // <DELETE id="smart-pointers">
00164 //     DynamicCast (qtRow, I->second);
00165 //     J = qtRow->tStringToTagMap.begin();
00166 //     for (; ( ( J != qtRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00167 // </DELETE>
00168     ptRow = I->second.dynamicCast<TTableRow*>();
00169     J     = ptRow->tStringToTagMap.begin();
00170     for (; ( ( J != ptRow->tStringToTagMap.end() ) && !qtTag ) ;++J)
00171     {
00172       //
00173       //  Searches for all items in all cells per row.
00174       //
00175 // <DELETE id="smart-pointers">
00176 //       DynamicCast (qtCell, J->second);
00177 //       K = qtCell->tStringToTagMap.find (yFirstIdentifierPart);
00178 //       if ( K != qtCell->tStringToTagMap.end() )
00179 // </DELETE>
00180       ptCell = J->second.dynamicCast<TTableCell*>();
00181       K      = ptCell->tStringToTagMap.find (yFirstIdentifierPart);
00182       if ( K != ptCell->tStringToTagMap.end() )
00183       {
00184         if ( !gHasMoreIdentifiers )
00185         {
00186           qtTag = K->second;
00187         }
00188         else
00189         {
00190 // <DELETE id="smart-pointers">
00191 //           DynamicCast (qtContainer, K->second);
00192 //           qtTag = qtContainer->findOrInsertTag (yLastIdentifierPart);
00193 // </DELETE>
00194           ptContainer = K->second.dynamicCast<TContainer*>();
00195           qtTag       = ptContainer->findOrInsertTag (yLastIdentifierPart);
00196         }
00197         break;
00198       }
00199     }
00200   }
00201   if ( !qtTag && isDynamiclyLoadable() && !gHasMoreIdentifiers )
00202   {
00203     qtTag = new TTag (rkyIDENTIFIER.c_str(), true);
00204 // <DELETE id="smart-pointers">
00205 //     qtRow = new TTableRow();
00206 //     qtRow->insert (new TTableCell (qtTag));
00207 //     insert (qtRow);
00208 // </DELETE>
00209     ptRow = new TTableRow();
00210     ptRow->insert (QTTag (new TTableCell (qtTag)));
00211     insert (QTTag (ptRow));
00212   }
00213   if ( !qtTag )
00214   {
00215     const char*   pkcFormat  = "in '%s' there is no tag called '%s'";
00216     TString       yMessage (Format (pkcFormat, identifier().c_str(), rkyIDENTIFIER.c_str()));
00217 
00218     throw TConstraintException (yMessage, __FILE__, __LINE__);
00219   }
00220   return qtTag;
00221 
00222 }  // findOrInsertTag()

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