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

clause_tag_string.cc

00001 /*
00002 *  Name:      clause_tag_string.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Clause-tag string
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 <mpcl/text/codegen/clause_tag_string.hh>
00027 #include <mpcl/text/codegen/defs.hh>
00028 #include <mpcl/text/regex/matcher.hh>
00029 
00030 
00031 //
00032 //  C O N S T R U C T O R S
00033 //
00034 
00035 void mpcl::text::codegen::TClauseTagString::
00036 overloadFrom (const TClauseTagString& rkySOURCE_CLAUSE_TAG)
00037 {
00038   
00039   assign (rkySOURCE_CLAUSE_TAG);
00040   gCheckParameters = rkySOURCE_CLAUSE_TAG.gCheckParameters;
00041   
00042 }  // overloadFrom()
00043 
00044 
00045 void mpcl::text::codegen::TClauseTagString::
00046 read (std::basic_istream<char_type, traits_type>& rtSOURCE_ISTREAM)
00047 {
00048 
00049   using std::basic_istream;
00050   using std::ios;
00051   using text::regex::TMatcher;
00052   
00053   bool                                             gHasTarget      = false;
00054   ios::iostate                                     tInitialIostate = rtSOURCE_ISTREAM.rdstate();
00055   basic_istream<char_type, traits_type>::pos_type  tInitialPos     = rtSOURCE_ISTREAM.tellg();
00056   TMatcher                                         tMatcher (rtSOURCE_ISTREAM);
00057 
00058   gCheckParameters = true;
00059   tMatcher.setCaseSensitiveness (false);
00060 
00061   //
00062   //  Remove comments if any, and then scans for the first part of the tag.
00063   //
00064   while ( tMatcher.scan (pkcCommentTagPattern, NULL) );
00065   if ( !tMatcher.scan (pkcCLAUSE_TagBegin, NULL) )
00066   {
00067     rtSOURCE_ISTREAM.setstate (std::ios::failbit);
00068   }
00069   else
00070   {
00071     //
00072     //  Gets the three possible attributes of the tag.
00073     //
00074     for (short int I = 0; ( I < 3 ) ;++I)
00075     {
00076       if ( !tMatcher.scan (pkcCLAUSE_TagNameAttr, (std::basic_string<char>*) this, NULL) )
00077       {
00078         if ( tMatcher.scan (pkcCLAUSE_TagTargetAttr, &yTarget, NULL) > 0 )
00079         {
00080           gHasTarget = true;
00081         }
00082         else
00083         {
00084           if ( !tMatcher.scan (pkcCLAUSE_TagNoCheckAttr, NULL) )
00085           {
00086             break;
00087           }
00088           else
00089           {
00090             gCheckParameters = false;
00091           }
00092         }
00093       }
00094     }
00095 
00096     //
00097     //  If it fails to match the ending pattern, then it
00098     //  changes the state of the stream, showing the error.
00099     //
00100     if ( !tMatcher.scan (pkcCLAUSE_TagEnd, NULL) )
00101     {
00102       rtSOURCE_ISTREAM.seekg (tInitialPos);
00103       rtSOURCE_ISTREAM.clear (tInitialIostate);
00104       rtSOURCE_ISTREAM.setstate (std::ios::failbit);
00105     }
00106     else
00107     {
00108       //
00109       //  If clause has target, then appends it to the clause name.
00110       //
00111       if ( !gHasTarget )
00112       {
00113         yTarget.erase();
00114       }
00115       else
00116       {
00117         append (pkcTargetSeparator);
00118         append (yTarget);
00119       }
00120     }
00121   }
00122 
00123 }  // read()
00124 
00125 
00126 //
00127 //  S E L E C T O R S
00128 //
00129 
00130 bool mpcl::text::codegen::TClauseTagString::
00131 mustCheckParameters (void) const
00132 {
00133 
00134   return gCheckParameters;
00135   
00136 }  // mustCheckParameters()
00137 
00138 
00139 const mpcl::text::TString& mpcl::text::codegen::TClauseTagString::
00140 name (void) const
00141 {
00142   
00143   return (const TString&) *this;
00144   
00145 }  // name()
00146 
00147 
00148 const mpcl::text::TString& mpcl::text::codegen::TClauseTagString::
00149 target (void) const
00150 {
00151   
00152   return yTarget;
00153   
00154 }  // target()
00155 
00156 
00157 void mpcl::text::codegen::TClauseTagString::
00158 write (std::basic_ostream<char_type, traits_type>& rtTARGET_OSTREAM) const
00159 {
00160   
00161   if ( yTarget.empty() )
00162   {
00163     rtTARGET_OSTREAM << "<clause name=\"";
00164     operator << (rtTARGET_OSTREAM, (std::string) *this);
00165     rtTARGET_OSTREAM << "\"";
00166   }
00167   else
00168   {
00169     size_type   zTargetSeparatorPosition;
00170     TString     yRealName;
00171     
00172     if ( npos == (zTargetSeparatorPosition = rfind (pkcTargetSeparator)) )
00173     {
00174       throw TBadInstantiateSyntaxException ("malformed name", __FILE__, __LINE__);
00175     }
00176     yRealName = substr (0, zTargetSeparatorPosition);
00177     rtTARGET_OSTREAM << "<clause name=\"" << yRealName << "\" target=\"" << yTarget << "\"";
00178   }
00179   if ( !gCheckParameters )
00180   {
00181     rtTARGET_OSTREAM << " nocheck";
00182   }
00183   rtTARGET_OSTREAM << ">";
00184   
00185 }  // write()

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