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

instruction_body.cc

00001 /*
00002 *  Name:      instruction_body.cc
00003 *  Author:    Rafael Jesus Alcantara Perez
00004 *  Summary:   Instruction body
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/defs.hh>
00027 #include <mpcl/text/codegen/instruction_body.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 mpcl::text::codegen::TInstructionBody& mpcl::text::codegen::TInstructionBody::
00036 operator = (const TInstructionBody& rktSOURCE_INSTRUCTION_BODY)
00037 {
00038 
00039   tClauseMap = rktSOURCE_INSTRUCTION_BODY.tClauseMap;
00040   return *this;
00041 
00042 }  // operator =()
00043 
00044 
00045 void mpcl::text::codegen::TInstructionBody::
00046 read (std::basic_istream<char_type, traits_type>& rtSOURCE_STREAM)
00047 {
00048 
00049   using text::regex::TMatcher;
00050 
00051   TMatcher   tMatcher (rtSOURCE_STREAM);
00052  
00053   tMatcher.setCaseSensitiveness (false);
00054 
00055   //
00056   //  Parse clauses.
00057   //
00058   rtSOURCE_STREAM >> tClauseMap;
00059 
00060   //
00061   //  Parse instruction end-tag.
00062   //
00063   while ( tMatcher.scan (pkcCommentTagPattern, NULL) );
00064   tMatcher.scan (pkcINSTRUCT_EndTagPattern, NULL);
00065 
00066 }  // read()
00067 
00068 
00069 //
00070 //  S E L E C T O R S
00071 //
00072 
00073 bool mpcl::text::codegen::TInstructionBody::
00074 existsClause (const char* pkcCLAUSE_NAME) const
00075 {
00076 
00077   return ( tClauseMap.end() != tClauseMap.find (pkcCLAUSE_NAME) );
00078 
00079 }  // existsClause()
00080 
00081 
00082 const mpcl::text::codegen::TClauseTagString& mpcl::text::codegen::TInstructionBody::
00083 clauseTag (const char* pkcSOURCE_CLAUSE_TAG) const
00084 {
00085 
00086   TClauseMap::const_iterator   ktIter = tClauseMap.find (pkcSOURCE_CLAUSE_TAG);
00087 
00088   if ( ktIter == tClauseMap.end() )
00089   {
00090     TString   yMessage;
00091     
00092     yMessage = Format ("clause '%s' not found", pkcSOURCE_CLAUSE_TAG);
00093     throw TNotFoundException (yMessage, __FILE__, __LINE__);
00094   }
00095   return ktIter->first;
00096 
00097 }  // clauseTag()
00098 
00099 
00100 const mpcl::text::codegen::TClauseBodyString& mpcl::text::codegen::TInstructionBody::
00101 clauseBody (const char* pkcSOURCE_CLAUSE_TAG) const
00102 {
00103 
00104   TClauseMap::const_iterator   ktIter = tClauseMap.find (pkcSOURCE_CLAUSE_TAG);
00105 
00106   if ( ktIter == tClauseMap.end() )
00107   {
00108     TString   yMessage;
00109     
00110     yMessage = Format ("clause '%s' not found", pkcSOURCE_CLAUSE_TAG);
00111     throw TNotFoundException (yMessage, __FILE__, __LINE__);
00112   }
00113   return ktIter->second;
00114 
00115 }  // clauseBody()
00116 
00117 
00118 mpcl::util::collection::TMap<mpcl::text::TString, const mpcl::text::codegen::TClauseBodyString*> mpcl::text::codegen::TInstructionBody::
00119 targetedVariablesForClause (const char* pkcSOURCE_CLAUSE_TAG) const
00120 {
00121 
00122   using util::collection::TMap;
00123 
00124   TString                                   yClauseName;
00125   TMap<TString, const TClauseBodyString*>   tResultMap;
00126   size_t                                    zSeparatorPosition;
00127   TClauseMap::const_iterator                ktIter = tClauseMap.begin();
00128   TClauseMap::const_iterator                ktEnd  = tClauseMap.end();
00129   
00130   for (; ( ktIter != ktEnd ) ;++ktIter)
00131   {
00132     const TClauseTagString&   rkyCurrentClauseTag = ktIter->first;
00133 
00134     yClauseName = rkyCurrentClauseTag;
00135     if ( TString::npos != (zSeparatorPosition = yClauseName.find (pkcTargetSeparator)) )
00136     {
00137       yClauseName.erase (zSeparatorPosition);
00138     }
00139     if ( yClauseName == pkcSOURCE_CLAUSE_TAG )
00140     {
00141       if ( rkyCurrentClauseTag.hasTarget() )
00142       {
00143         tResultMap.bind (rkyCurrentClauseTag.target(), &ktIter->second);
00144       }
00145     }
00146   }
00147   return tResultMap;
00148 
00149 }  // targetedVariablesForClause()
00150 
00151 
00152 const mpcl::text::codegen::TClauseBodyString& mpcl::text::codegen::TInstructionBody::
00153 operator [] (const char* pkcSOURCE_CLAUSE_TAG) const
00154 {
00155 
00156   TClauseMap::const_iterator   ktIter = tClauseMap.find (pkcSOURCE_CLAUSE_TAG);
00157   
00158   if ( ktIter == tClauseMap.end() )
00159   {
00160     TString   yMessage;
00161     
00162     yMessage = Format ("clause '%s' not found", pkcSOURCE_CLAUSE_TAG);
00163     throw TNotFoundException (yMessage, __FILE__, __LINE__);
00164   }
00165   return ktIter->second;
00166 
00167 }  // operator []()
00168 
00169 
00170 bool mpcl::text::codegen::TInstructionBody::
00171 operator == (const TInstructionBody& rktSOURCE_INSTRUCTION_BODY) const
00172 {
00173 
00174   return ( tClauseMap == rktSOURCE_INSTRUCTION_BODY.tClauseMap );
00175 
00176 }  // operator ==()
00177 
00178 
00179 void mpcl::text::codegen::TInstructionBody::
00180 write (std::basic_ostream<char_type, traits_type>& rtTARGET_STREAM) const
00181 {
00182 
00183   rtTARGET_STREAM << tClauseMap << "</instruct>\n";
00184 
00185 }  // write()

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