00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <cstdarg>
00027 #include <mpcl/text/codegen/clause_body_string.hh>
00028 #include <mpcl/text/regex/matcher.hh>
00029
00030
00031
00032
00033
00034
00035 mpcl::text::codegen::TClauseBodyString& mpcl::text::codegen::TClauseBodyString::
00036 operator = (const TClauseBodyString& rkySOURCE_CLAUSE_BODY)
00037 {
00038
00039 TString::operator = (rkySOURCE_CLAUSE_BODY);
00040 return *this;
00041
00042 }
00043
00044
00045 void mpcl::text::codegen::TClauseBodyString::
00046 read (std::basic_istream<char_type, traits_type>& rtSOURCE_ISTREAM)
00047 {
00048
00049 using text::regex::TMatcher;
00050 using std::basic_string;
00051
00052 TMatcher tMatcher (rtSOURCE_ISTREAM);
00053
00054 tMatcher.setCaseSensitiveness (false);
00055 tMatcher.scan (pkcCLAUSE_BodyPattern, (basic_string<char>*) this, NULL);
00056
00057 }
00058
00059
00060
00061
00062
00063
00064 mpcl::text::TString mpcl::text::codegen::TClauseBodyString::
00065 instantiate ( const char* pkcFIRST_PARAMETER_NAME ,
00066 const char* pkcFIRST_PARAMETER_VALUE... ) const
00067 {
00068
00069
00070
00071
00072
00073 const char* pkcTag;
00074 const char* pkcValue;
00075 va_list tVa_list;
00076 TString yParameterTag;
00077 TString yInstance (preprocess());
00078
00079
00080
00081
00082 yParameterTag = Format ("%%%s%%", pkcFIRST_PARAMETER_NAME);
00083 if ( !gParameterExistenceSensitiveness )
00084 {
00085 yInstance.replaceAll (yParameterTag, pkcFIRST_PARAMETER_VALUE);
00086 va_start (tVa_list, pkcFIRST_PARAMETER_VALUE);
00087 while ( NULL != (pkcTag = va_arg (tVa_list, char*)) )
00088 {
00089 if ( NULL == (pkcValue = va_arg (tVa_list, char*)) )
00090 {
00091 throw TBadInstantiateSyntaxException ("you must give tag-value pairs", __FILE__, __LINE__);
00092 }
00093 else
00094 {
00095 yParameterTag = Format ("%%%s%%", pkcTag);
00096 yInstance.replaceAll (yParameterTag, pkcValue);
00097 }
00098 }
00099 }
00100 else
00101 {
00102 if ( !yInstance.replaceAll (yParameterTag, pkcFIRST_PARAMETER_VALUE) )
00103 {
00104 TString yMessage = Format ( "there is no tag called '%s' in this clause code" ,
00105 pkcFIRST_PARAMETER_NAME );
00106
00107 throw TBadInstantiateSyntaxException (yMessage, __FILE__, __LINE__);
00108 }
00109 else
00110 {
00111 va_start (tVa_list, pkcFIRST_PARAMETER_VALUE);
00112 while ( NULL != (pkcTag = va_arg (tVa_list, char*)) )
00113 {
00114 if ( NULL == (pkcValue = va_arg (tVa_list, char*)) )
00115 {
00116 throw TBadInstantiateSyntaxException ("you must give tag-value pairs", __FILE__, __LINE__);
00117 }
00118 else
00119 {
00120 yParameterTag = Format ("%%%s%%", pkcTag);
00121 if ( !yInstance.replaceAll (yParameterTag, pkcValue) )
00122 {
00123 TString yMessage = Format ("there is no tag called '%s' in this clause code", pkcTag);
00124
00125 throw TBadInstantiateSyntaxException (yMessage, __FILE__, __LINE__);
00126 }
00127 }
00128 }
00129 }
00130 }
00131 return yInstance;
00132
00133 }
00134
00135
00136 mpcl::text::TString mpcl::text::codegen::TClauseBodyString::
00137 instantiate ( const TStringToVariableMap& rktSOURCE_VARIABLE_MAP ,
00138 bool gPARAMETER_EXISTENCE_SENSITIVENESS ) const
00139 {
00140
00141
00142
00143
00144
00145 TString yParameterTag;
00146 TString yInstance = preprocess();
00147 TStringToVariableMap::const_iterator I = rktSOURCE_VARIABLE_MAP.begin();
00148 TStringToVariableMap::const_iterator ktEnd = rktSOURCE_VARIABLE_MAP.end();
00149
00150
00151
00152
00153 if ( !gPARAMETER_EXISTENCE_SENSITIVENESS )
00154 {
00155 for (; ( I != ktEnd ) ;++I)
00156 {
00157 yParameterTag = Format ("%%%s%%", I->first.c_str());
00158 yInstance.replaceAll (yParameterTag, I->second);
00159 }
00160 }
00161 else
00162 {
00163 for (; ( I != ktEnd ) ;++I)
00164 {
00165 yParameterTag = Format ("%%%s%%", I->first.c_str());
00166 if ( !yInstance.replaceAll (yParameterTag, I->second) )
00167 {
00168 if ( I->second.type() == TVariableString::eNormal )
00169 {
00170
00171
00172
00173
00174 TString yMessage = Format ( "there is no tag called '%s' in this clause code" ,
00175 I->first.c_str() );
00176
00177 throw TBadInstantiateSyntaxException (yMessage, __FILE__, __LINE__);
00178 }
00179 }
00180 }
00181 }
00182 return yInstance;
00183
00184 }
00185
00186
00187 mpcl::text::TString mpcl::text::codegen::TClauseBodyString::
00188 instantiate ( const TStringToStringMap& rktSOURCE_STRING_MAP ,
00189 bool gPARAMETER_EXISTENCE_SENSITIVENESS ) const
00190 {
00191
00192
00193
00194
00195
00196 TString yParameterTag;
00197 TString yInstance = preprocess();
00198 TStringToStringMap::const_iterator I = rktSOURCE_STRING_MAP.begin();
00199 TStringToStringMap::const_iterator ktEnd = rktSOURCE_STRING_MAP.end();
00200
00201
00202
00203
00204 if ( !gPARAMETER_EXISTENCE_SENSITIVENESS )
00205 {
00206 for (; ( I != ktEnd ) ;++I)
00207 {
00208 yParameterTag = Format ("%%%s%%", I->first.c_str());
00209 yInstance.replaceAll (yParameterTag, I->second);
00210 }
00211 }
00212 else
00213 {
00214 for (; ( I != ktEnd ) ;++I)
00215 {
00216 yParameterTag = Format ("%%%s%%", I->first.c_str());
00217 if ( !yInstance.replaceAll (yParameterTag, I->second) )
00218 {
00219
00220
00221
00222
00223 TString yMessage = Format ( "there is no tag called '%s' in this clause code" ,
00224 I->first.c_str() );
00225
00226 throw TBadInstantiateSyntaxException (yMessage, __FILE__, __LINE__);
00227 }
00228 }
00229 }
00230 return yInstance;
00231
00232 }
00233
00234
00235 void mpcl::text::codegen::TClauseBodyString::
00236 write (std::basic_ostream<char_type, traits_type>& rtTARGET_OSTREAM) const
00237 {
00238
00239 operator << (rtTARGET_OSTREAM, (std::string) *this);
00240 rtTARGET_OSTREAM << "</clause>\n";
00241
00242 }
00243
00244
00245 mpcl::text::TString mpcl::text::codegen::TClauseBodyString::
00246 preprocess (void) const
00247 {
00248
00249 TString yInstance (*this);
00250
00251
00252
00253
00254 InstantiateEntities (yInstance);
00255 return yInstance;
00256
00257 }