2013-03-21 15:37:40 +01:00
/*
Copyright 2013 Statoil ASA .
This file is part of the Open Porous Media project ( OPM ) .
OPM is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
OPM is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with OPM . If not , see < http : //www.gnu.org/licenses/>.
2013-04-08 10:36:14 +02:00
*/
2013-03-21 15:37:40 +01:00
# include <string>
# include <stdexcept>
2013-07-30 14:10:07 +02:00
2013-08-06 16:26:49 +02:00
2013-07-30 14:10:07 +02:00
# include <opm/json/JsonObject.hpp>
2013-04-02 15:19:32 +02:00
# include <opm/parser/eclipse/Parser/ParserConst.hpp>
2013-06-20 15:30:37 +02:00
# include <opm/parser/eclipse/Parser/ParserKeyword.hpp>
2013-07-31 17:58:05 +02:00
# include <opm/parser/eclipse/Parser/ParserIntItem.hpp>
2013-08-01 09:31:27 +02:00
# include <opm/parser/eclipse/Parser/ParserDoubleItem.hpp>
2013-07-31 17:58:05 +02:00
# include <opm/parser/eclipse/Parser/ParserStringItem.hpp>
2013-03-21 15:37:40 +01:00
2013-08-01 09:31:27 +02:00
2013-03-21 15:37:40 +01:00
namespace Opm {
2013-04-08 10:36:14 +02:00
2013-12-04 15:31:28 +01:00
void ParserKeyword : : commonInit ( const std : : string & name , ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action ) {
2013-10-08 13:46:55 +02:00
if ( ! validName ( name ) )
throw std : : invalid_argument ( " Invalid name: " + name + " keyword must be all upper case, max 8 characters. Starting with character. " ) ;
2013-11-08 15:55:11 +01:00
2013-10-08 13:46:55 +02:00
m_isDataKeyword = false ;
m_isTableCollection = false ;
m_name = name ;
m_action = action ;
m_record = ParserRecordPtr ( new ParserRecord ) ;
2013-12-04 15:31:28 +01:00
m_keywordSizeType = sizeType ;
2013-06-24 14:08:53 +02:00
}
2013-12-04 14:26:08 +01:00
ParserKeyword : : ParserKeyword ( const std : : string & name , ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action ) {
2013-12-04 15:31:28 +01:00
if ( ! ( sizeType = = SLASH_TERMINATED | | sizeType = = UNKNOWN ) ) {
throw std : : invalid_argument ( " Size type " + ParserKeywordSizeEnum2String ( sizeType ) + " can not be set explicitly. " ) ;
}
commonInit ( name , sizeType , action ) ;
2013-07-30 14:10:07 +02:00
}
2013-12-04 14:26:08 +01:00
ParserKeyword : : ParserKeyword ( const char * name , ParserKeywordSizeEnum sizeType , ParserKeywordActionEnum action ) {
if ( ! ( sizeType = = SLASH_TERMINATED | | sizeType = = UNKNOWN ) ) {
throw std : : invalid_argument ( " Size type " + ParserKeywordSizeEnum2String ( sizeType ) + " can not be set explicitly. " ) ;
}
2013-12-04 15:31:28 +01:00
commonInit ( name , sizeType , action ) ;
2013-10-01 16:35:55 +02:00
}
2013-11-08 15:55:11 +01:00
ParserKeyword : : ParserKeyword ( const std : : string & name , size_t fixedKeywordSize , ParserKeywordActionEnum action ) {
2013-12-04 15:31:28 +01:00
commonInit ( name , FIXED , action ) ;
2013-06-24 14:08:53 +02:00
m_fixedSize = fixedKeywordSize ;
2013-05-06 12:13:49 +02:00
}
2013-10-08 13:46:55 +02:00
2013-11-08 15:55:11 +01:00
ParserKeyword : : ParserKeyword ( const std : : string & name , const std : : string & sizeKeyword , const std : : string & sizeItem , ParserKeywordActionEnum action , bool isTableCollection ) {
2013-12-04 15:31:28 +01:00
commonInit ( name , OTHER_KEYWORD_IN_DECK , action ) ;
2013-10-08 13:46:55 +02:00
m_isTableCollection = isTableCollection ;
2013-11-08 15:55:11 +01:00
initSizeKeyword ( sizeKeyword , sizeItem ) ;
2013-10-08 13:46:55 +02:00
}
2013-12-09 21:12:27 +01:00
bool ParserKeyword : : hasDimension ( ) const {
return m_record - > hasDimension ( ) ;
}
2013-10-01 16:35:55 +02:00
bool ParserKeyword : : isTableCollection ( ) const {
return m_isTableCollection ;
}
2013-07-31 17:58:05 +02:00
2013-11-08 15:55:11 +01:00
void ParserKeyword : : initSize ( const Json : : JsonObject & jsonConfig ) {
2013-09-22 17:23:27 +02:00
// The number of record has been set explicitly with the size: keyword
2013-07-31 17:58:05 +02:00
if ( jsonConfig . has_item ( " size " ) ) {
2013-08-06 16:26:49 +02:00
Json : : JsonObject sizeObject = jsonConfig . get_item ( " size " ) ;
2013-11-08 15:55:11 +01:00
2013-08-06 16:26:49 +02:00
if ( sizeObject . is_number ( ) ) {
2013-11-08 15:55:11 +01:00
m_fixedSize = ( size_t ) sizeObject . as_int ( ) ;
2013-08-06 16:26:49 +02:00
m_keywordSizeType = FIXED ;
2013-10-01 17:13:40 +02:00
} else
2013-11-08 15:55:11 +01:00
initSizeKeyword ( sizeObject ) ;
2013-10-01 17:13:40 +02:00
} else
if ( jsonConfig . has_item ( " num_tables " ) ) {
2013-11-08 15:55:11 +01:00
Json : : JsonObject numTablesObject = jsonConfig . get_item ( " num_tables " ) ;
2013-10-01 17:13:40 +02:00
2013-11-08 15:55:11 +01:00
if ( ! numTablesObject . is_object ( ) )
throw std : : invalid_argument ( " The num_tables key must point to a {} object " ) ;
2013-10-01 17:13:40 +02:00
2013-11-08 15:55:11 +01:00
initSizeKeyword ( numTablesObject ) ;
m_isTableCollection = true ;
2013-09-22 17:23:27 +02:00
} else {
if ( jsonConfig . has_item ( " items " ) )
// The number of records is undetermined - the keyword will be '/' terminated.
2013-10-01 15:50:43 +02:00
m_keywordSizeType = SLASH_TERMINATED ;
2013-09-22 17:23:27 +02:00
else {
m_keywordSizeType = FIXED ;
if ( jsonConfig . has_item ( " data " ) )
m_fixedSize = 1 ;
else
m_fixedSize = 0 ;
}
}
}
ParserKeyword : : ParserKeyword ( const Json : : JsonObject & jsonConfig ) {
2013-10-08 14:13:45 +02:00
ParserKeywordActionEnum action = INTERNALIZE ;
if ( jsonConfig . has_item ( " action " ) )
2013-11-08 15:55:11 +01:00
action = ParserKeywordActionEnumFromString ( jsonConfig . get_string ( " action " ) ) ;
2013-09-22 17:23:27 +02:00
if ( jsonConfig . has_item ( " name " ) ) {
2013-12-04 15:31:28 +01:00
ParserKeywordSizeEnum sizeType = UNKNOWN ;
commonInit ( jsonConfig . get_string ( " name " ) , sizeType , action ) ;
2013-07-31 17:58:05 +02:00
} else
2013-09-22 17:23:27 +02:00
throw std : : invalid_argument ( " Json object is missing name: property " ) ;
2013-11-08 15:55:11 +01:00
initSize ( jsonConfig ) ;
if ( jsonConfig . has_item ( " items " ) )
addItems ( jsonConfig ) ;
2013-07-31 17:58:05 +02:00
2013-09-22 17:23:27 +02:00
if ( jsonConfig . has_item ( " data " ) )
2013-11-08 15:55:11 +01:00
initData ( jsonConfig ) ;
2013-09-22 17:23:27 +02:00
2013-10-01 17:13:40 +02:00
if ( isTableCollection ( ) )
addTableItems ( ) ;
2013-10-08 14:13:45 +02:00
if ( ( m_fixedSize = = 0 & & m_keywordSizeType = = FIXED ) | | ( m_action ! = INTERNALIZE ) )
2013-09-22 17:23:27 +02:00
return ;
2013-11-08 15:55:11 +01:00
else {
2013-09-22 17:23:27 +02:00
if ( numItems ( ) = = 0 )
throw std : : invalid_argument ( " Json object for keyword: " + jsonConfig . get_string ( " name " ) + " is missing items specifier " ) ;
}
2013-07-30 14:10:07 +02:00
}
2013-07-31 17:58:05 +02:00
2013-11-08 15:55:11 +01:00
void ParserKeyword : : initSizeKeyword ( const std : : string & sizeKeyword , const std : : string & sizeItem ) {
m_sizeDefinitionPair = std : : pair < std : : string , std : : string > ( sizeKeyword , sizeItem ) ;
2013-12-04 15:31:28 +01:00
m_keywordSizeType = OTHER_KEYWORD_IN_DECK ;
2013-08-06 16:26:49 +02:00
}
2013-10-01 17:13:40 +02:00
void ParserKeyword : : initSizeKeyword ( const Json : : JsonObject & sizeObject ) {
2013-12-05 08:26:29 +01:00
if ( sizeObject . is_object ( ) ) {
std : : string sizeKeyword = sizeObject . get_string ( " keyword " ) ;
std : : string sizeItem = sizeObject . get_string ( " item " ) ;
initSizeKeyword ( sizeKeyword , sizeItem ) ;
} else {
m_keywordSizeType = ParserKeywordSizeEnumFromString ( sizeObject . as_string ( ) ) ;
}
2013-10-01 17:13:40 +02:00
}
2013-12-01 09:25:52 +01:00
2013-12-02 11:19:22 +01:00
bool ParserKeyword : : validNameStart ( const std : : string & name ) {
2013-12-01 09:25:52 +01:00
if ( name . length ( ) > ParserConst : : maxKeywordLength )
return false ;
if ( ! isupper ( name [ 0 ] ) )
return false ;
2013-12-02 11:19:22 +01:00
return true ;
}
bool ParserKeyword : : wildCardName ( const std : : string & name ) {
if ( ! validNameStart ( name ) )
return false ;
2013-12-02 11:10:53 +01:00
for ( size_t i = 1 ; i < name . length ( ) ; i + + ) {
2013-12-01 09:25:52 +01:00
char c = name [ i ] ;
if ( ! ( isupper ( c ) | | isdigit ( c ) ) ) {
if ( ( i = = ( name . length ( ) - 1 ) ) & & ( c = = ' * ' ) )
return true ;
else
return false ;
}
}
return false ;
}
2013-08-21 12:43:15 +02:00
bool ParserKeyword : : validName ( const std : : string & name ) {
2013-12-02 11:19:22 +01:00
if ( ! validNameStart ( name ) )
2013-08-21 23:15:40 +02:00
return false ;
2013-11-08 15:55:11 +01:00
2013-12-02 11:10:53 +01:00
for ( size_t i = 1 ; i < name . length ( ) ; i + + ) {
2013-08-21 23:15:40 +02:00
char c = name [ i ] ;
2013-12-01 09:25:52 +01:00
if ( ! ( isupper ( c ) | | isdigit ( c ) ) )
return wildCardName ( name ) ;
2013-08-21 23:15:40 +02:00
}
return true ;
2013-08-21 12:43:15 +02:00
}
2013-12-02 11:19:22 +01:00
2013-11-08 15:55:11 +01:00
void ParserKeyword : : addItem ( ParserItemConstPtr item ) {
2013-09-22 17:23:27 +02:00
if ( m_isDataKeyword )
throw std : : invalid_argument ( " Keyword: " + getName ( ) + " is already configured as data keyword - can not add more items. " ) ;
2013-11-08 15:55:11 +01:00
m_record - > addItem ( item ) ;
2013-09-13 22:23:12 +02:00
}
2013-11-08 15:55:11 +01:00
void ParserKeyword : : addDataItem ( ParserItemConstPtr item ) {
2013-09-22 17:23:27 +02:00
if ( m_record - > size ( ) )
throw std : : invalid_argument ( " Keyword: " + getName ( ) + " already has items - can not add a data item. " ) ;
2013-11-08 15:55:11 +01:00
2013-09-22 17:23:27 +02:00
if ( ( m_fixedSize = = 1U ) & & ( m_keywordSizeType = = FIXED ) ) {
2013-11-08 15:55:11 +01:00
addItem ( item ) ;
2013-09-22 17:23:27 +02:00
m_isDataKeyword = true ;
} else
throw std : : invalid_argument ( " Keyword: " + getName ( ) + " . When calling addDataItem() the keyword must be configured with fixed size == 1. " ) ;
}
2013-11-08 15:55:11 +01:00
void ParserKeyword : : addItems ( const Json : : JsonObject & jsonConfig ) {
2013-07-31 17:58:05 +02:00
const Json : : JsonObject itemsConfig = jsonConfig . get_item ( " items " ) ;
if ( itemsConfig . is_array ( ) ) {
size_t num_items = itemsConfig . size ( ) ;
2013-11-08 15:55:11 +01:00
for ( size_t i = 0 ; i < num_items ; i + + ) {
const Json : : JsonObject itemConfig = itemsConfig . get_array_item ( i ) ;
2013-07-31 17:58:05 +02:00
if ( itemConfig . has_item ( " value_type " ) ) {
2013-11-08 15:55:11 +01:00
ParserValueTypeEnum valueType = ParserValueTypeEnumFromString ( itemConfig . get_string ( " value_type " ) ) ;
switch ( valueType ) {
case INT :
2013-07-31 17:58:05 +02:00
{
2013-11-08 15:55:11 +01:00
ParserIntItemConstPtr item = ParserIntItemConstPtr ( new ParserIntItem ( itemConfig ) ) ;
addItem ( item ) ;
2013-07-31 17:58:05 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
case STRING :
2013-07-31 17:58:05 +02:00
{
2013-11-08 15:55:11 +01:00
ParserStringItemConstPtr item = ParserStringItemConstPtr ( new ParserStringItem ( itemConfig ) ) ;
addItem ( item ) ;
2013-07-31 17:58:05 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
case FLOAT :
2013-08-01 09:31:27 +02:00
{
2013-12-10 17:35:20 +01:00
ParserDoubleItemPtr item = ParserDoubleItemPtr ( new ParserDoubleItem ( itemConfig ) ) ;
initItemDimension ( item , itemConfig ) ;
2013-11-08 15:55:11 +01:00
addItem ( item ) ;
2013-08-01 09:31:27 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
default :
throw std : : invalid_argument ( " Not implemented. " ) ;
2013-07-31 17:58:05 +02:00
}
} else
2013-11-08 15:55:11 +01:00
throw std : : invalid_argument ( " Json config object missing \" value_type \" : ... item " ) ;
2013-07-31 17:58:05 +02:00
}
} else
2013-11-08 15:55:11 +01:00
throw std : : invalid_argument ( " The items: object must be an array " ) ;
2013-07-31 17:58:05 +02:00
}
2013-10-01 17:13:40 +02:00
void ParserKeyword : : addTableItems ( ) {
2013-11-08 15:55:11 +01:00
ParserDoubleItemConstPtr item = ParserDoubleItemConstPtr ( new ParserDoubleItem ( " TABLEROW " , ALL , 0 ) ) ;
addItem ( item ) ;
2013-10-01 17:13:40 +02:00
}
2013-12-10 17:35:20 +01:00
void ParserKeyword : : initItemDimension ( ParserDoubleItemPtr item , const Json : : JsonObject itemConfig ) {
if ( itemConfig . has_item ( " dimension " ) ) {
const Json : : JsonObject dimensionConfig = itemConfig . get_item ( " dimension " ) ;
if ( dimensionConfig . is_string ( ) )
item - > push_backDimension ( dimensionConfig . as_string ( ) ) ;
else if ( dimensionConfig . is_array ( ) ) {
for ( size_t idim = 0 ; idim < dimensionConfig . size ( ) ; idim + + ) {
Json : : JsonObject dimObject = dimensionConfig . get_array_item ( idim ) ;
item - > push_backDimension ( dimObject . as_string ( ) ) ;
}
} else
throw std : : invalid_argument ( " The dimension: attribute must be a string/list of strings " ) ;
}
}
2013-09-22 17:23:27 +02:00
void ParserKeyword : : initData ( const Json : : JsonObject & jsonConfig ) {
m_fixedSize = 1U ;
m_keywordSizeType = FIXED ;
const Json : : JsonObject dataConfig = jsonConfig . get_item ( " data " ) ;
if ( dataConfig . has_item ( " value_type " ) ) {
2013-11-08 15:55:11 +01:00
ParserValueTypeEnum valueType = ParserValueTypeEnumFromString ( dataConfig . get_string ( " value_type " ) ) ;
const std : : string itemName ( getName ( ) ) ;
2013-09-22 17:23:27 +02:00
bool hasDefault = dataConfig . has_item ( " default " ) ;
2013-11-08 15:55:11 +01:00
switch ( valueType ) {
2013-09-22 17:23:27 +02:00
case INT :
{
2013-11-08 15:55:11 +01:00
ParserIntItemPtr item = ParserIntItemPtr ( new ParserIntItem ( itemName , ALL ) ) ;
2013-09-22 17:23:27 +02:00
if ( hasDefault ) {
int defaultValue = dataConfig . get_int ( " default " ) ;
2013-11-08 15:55:11 +01:00
item - > setDefault ( defaultValue ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
addDataItem ( item ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
case STRING :
2013-09-22 17:23:27 +02:00
{
2013-11-08 15:55:11 +01:00
ParserStringItemPtr item = ParserStringItemPtr ( new ParserStringItem ( itemName , ALL ) ) ;
2013-09-22 17:23:27 +02:00
if ( hasDefault ) {
std : : string defaultValue = dataConfig . get_string ( " default " ) ;
2013-11-08 15:55:11 +01:00
item - > setDefault ( defaultValue ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
addDataItem ( item ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
case FLOAT :
2013-09-22 17:23:27 +02:00
{
2013-11-08 15:55:11 +01:00
ParserDoubleItemPtr item = ParserDoubleItemPtr ( new ParserDoubleItem ( itemName , ALL ) ) ;
2013-09-22 17:23:27 +02:00
if ( hasDefault ) {
double defaultValue = dataConfig . get_double ( " default " ) ;
2013-11-08 15:55:11 +01:00
item - > setDefault ( defaultValue ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
addDataItem ( item ) ;
2013-09-22 17:23:27 +02:00
}
2013-11-08 15:55:11 +01:00
break ;
default :
throw std : : invalid_argument ( " Not implemented. " ) ;
}
2013-09-22 17:23:27 +02:00
} else
2013-11-08 15:55:11 +01:00
throw std : : invalid_argument ( " Json config object missing \" value_type \" : ... item " ) ;
2013-09-22 17:23:27 +02:00
}
2013-08-26 15:17:52 +02:00
ParserRecordPtr ParserKeyword : : getRecord ( ) const {
2013-05-27 14:28:23 +02:00
return m_record ;
}
2013-06-21 15:34:06 +02:00
2013-10-08 13:46:55 +02:00
ParserKeywordActionEnum ParserKeyword : : getAction ( ) const {
return m_action ;
}
2013-06-20 15:30:37 +02:00
const std : : string & ParserKeyword : : getName ( ) const {
2013-05-06 12:13:49 +02:00
return m_name ;
}
2013-03-21 15:37:40 +01:00
2013-08-21 23:15:40 +02:00
size_t ParserKeyword : : numItems ( ) const {
return m_record - > size ( ) ;
}
2013-06-20 15:30:37 +02:00
DeckKeywordPtr ParserKeyword : : parse ( RawKeywordConstPtr rawKeyword ) const {
2013-12-01 09:28:14 +01:00
DeckKeywordPtr keyword ( new DeckKeyword ( rawKeyword - > getKeywordName ( ) ) ) ;
2013-06-21 15:34:06 +02:00
for ( size_t i = 0 ; i < rawKeyword - > size ( ) ; i + + ) {
DeckRecordConstPtr deckRecord = m_record - > parse ( rawKeyword - > getRecord ( i ) ) ;
keyword - > addRecord ( deckRecord ) ;
2013-06-03 15:54:16 +02:00
}
return keyword ;
2013-05-27 14:28:23 +02:00
}
2013-06-24 14:08:53 +02:00
2013-06-21 15:34:06 +02:00
size_t ParserKeyword : : getFixedSize ( ) const {
2013-06-24 14:08:53 +02:00
if ( ! hasFixedSize ( ) ) {
throw std : : logic_error ( " This parser keyword does not have a fixed size! " ) ;
}
return m_fixedSize ;
2013-06-21 15:34:06 +02:00
}
2013-06-24 14:08:53 +02:00
bool ParserKeyword : : hasFixedSize ( ) const {
return m_keywordSizeType = = FIXED ;
}
2013-08-06 16:26:49 +02:00
enum ParserKeywordSizeEnum ParserKeyword : : getSizeType ( ) const {
return m_keywordSizeType ;
}
2013-11-08 15:55:11 +01:00
const std : : pair < std : : string , std : : string > & ParserKeyword : : getSizeDefinitionPair ( ) const {
2013-08-14 08:43:54 +02:00
return m_sizeDefinitionPair ;
2013-08-06 16:26:49 +02:00
}
2013-09-22 17:23:27 +02:00
bool ParserKeyword : : isDataKeyword ( ) const {
return m_isDataKeyword ;
}
2013-12-01 09:25:52 +01:00
bool ParserKeyword : : matches ( const std : : string & keyword ) const {
size_t cmpLength = m_name . find ( ' * ' ) ;
if ( cmpLength = = std : : string : : npos )
return ( keyword = = m_name ) ;
else {
if ( keyword . length ( ) < cmpLength )
return false ;
return ( m_name . compare ( 0 , cmpLength , keyword , 0 , cmpLength ) = = 0 ) ;
}
}
2013-09-13 22:23:12 +02:00
bool ParserKeyword : : equal ( const ParserKeyword & other ) const {
if ( ( m_name = = other . m_name ) & &
2013-11-08 15:55:11 +01:00
( m_record - > equal ( * ( other . m_record ) ) ) & &
( m_keywordSizeType = = other . m_keywordSizeType ) & &
( m_isDataKeyword = = other . m_isDataKeyword ) & &
( m_isTableCollection = = other . m_isTableCollection ) & &
( m_action = = other . m_action ) ) {
bool equal = false ;
switch ( m_keywordSizeType ) {
2013-09-13 22:23:12 +02:00
case FIXED :
if ( m_fixedSize = = other . m_fixedSize )
equal = true ;
break ;
2013-12-04 14:26:08 +01:00
case OTHER_KEYWORD_IN_DECK :
2013-11-08 15:55:11 +01:00
if ( ( m_sizeDefinitionPair . first = = other . m_sizeDefinitionPair . first ) & &
( m_sizeDefinitionPair . second = = other . m_sizeDefinitionPair . second ) )
2013-09-13 22:23:12 +02:00
equal = true ;
break ;
2013-12-04 14:26:08 +01:00
default :
equal = true ;
break ;
2013-09-13 22:23:12 +02:00
}
2013-11-08 15:55:11 +01:00
return equal ;
} else
2013-09-13 22:23:12 +02:00
return false ;
}
2013-11-08 15:55:11 +01:00
void ParserKeyword : : inlineNew ( std : : ostream & os , const std : : string & lhs , const std : : string & indent ) const {
{
const std : : string actionString ( ParserKeywordActionEnum2String ( m_action ) ) ;
2013-12-04 15:31:28 +01:00
const std : : string sizeString ( ParserKeywordSizeEnum2String ( m_keywordSizeType ) ) ;
2013-11-08 15:55:11 +01:00
switch ( m_keywordSizeType ) {
case SLASH_TERMINATED :
2013-12-04 15:31:28 +01:00
os < < lhs < < " = new ParserKeyword( \" " < < m_name < < " \" , " < < sizeString < < " , " < < actionString < < " ); " < < std : : endl ;
break ;
case UNKNOWN :
os < < lhs < < " = new ParserKeyword( \" " < < m_name < < " \" , " < < sizeString < < " , " < < actionString < < " ); " < < std : : endl ;
2013-11-08 15:55:11 +01:00
break ;
case FIXED :
os < < lhs < < " = new ParserKeyword( \" " < < m_name < < " \" ,(size_t) " < < m_fixedSize < < " , " < < actionString < < " ); " < < std : : endl ;
break ;
2013-12-04 14:26:08 +01:00
case OTHER_KEYWORD_IN_DECK :
2013-11-08 15:55:11 +01:00
if ( isTableCollection ( ) )
os < < lhs < < " = new ParserKeyword( \" " < < m_name < < " \" , \" " < < m_sizeDefinitionPair . first < < " \" , \" " < < m_sizeDefinitionPair . second < < " \" , " < < actionString < < " , true); " < < std : : endl ;
else
os < < lhs < < " = new ParserKeyword( \" " < < m_name < < " \" , \" " < < m_sizeDefinitionPair . first < < " \" , \" " < < m_sizeDefinitionPair . second < < " \" , " < < actionString < < " ); " < < std : : endl ;
break ;
}
}
for ( size_t i = 0 ; i < m_record - > size ( ) ; i + + ) {
os < < indent < < " { " < < std : : endl ;
{
const std : : string local_indent = indent + " " ;
ParserItemConstPtr item = m_record - > get ( i ) ;
os < < local_indent < < " ParserItemConstPtr item( " ;
item - > inlineNew ( os ) ;
os < < " ); " < < std : : endl ;
{
std : : string addItemMethod = " addItem " ;
if ( m_isDataKeyword )
addItemMethod = " addDataItem " ;
2013-09-13 22:23:12 +02:00
2013-11-08 15:55:11 +01:00
os < < local_indent < < lhs < < " -> " < < addItemMethod < < " (item); " < < std : : endl ;
}
}
os < < indent < < " } " < < std : : endl ;
}
}
2013-03-21 15:37:40 +01:00
}