28 #include <boost/lexical_cast.hpp>
46 virtual const std::string&
getDimension(
size_t index)
const;
51 const std::string&
name()
const;
58 virtual void inlineClass(std::ostream& ,
const std::string& indent)
const = 0;
59 virtual std::string
inlineClassInit(
const std::string& parentClass)
const = 0;
69 const T * lhs =
dynamic_cast<const T*
>(
this);
70 const T * rhs =
dynamic_cast<const T*
>(&other);
74 if (lhs->name() != rhs->name())
77 if (lhs->getDescription() != rhs->getDescription())
80 if (lhs->sizeType() != rhs->sizeType())
83 if (lhs->m_defaultSet != rhs->m_defaultSet)
88 if (lhs->m_defaultSet && lhs->getDefault() != rhs->getDefault())
99 std::string m_description;
107 template<
typename ParserItemType,
typename ValueType>
109 os << indent <<
"class " <<
self->className( ) <<
" {" << std::endl;
110 os << indent <<
"public:" << std::endl;
112 std::string local_indent = indent +
" ";
113 os << local_indent <<
"static const std::string itemName;" << std::endl;
114 if (self->hasDefault())
115 os << local_indent <<
"static const " << typeString <<
" defaultValue;" << std::endl;
117 os << indent <<
"};" << std::endl;
121 template<
typename ParserItemType,
typename ValueType>
123 const std::string& parentClass ,
124 const std::string& typeString ,
125 const std::string * defaultValue = NULL) {
127 std::stringstream ss;
128 ss <<
"const std::string " << parentClass <<
"::" <<
self->className() <<
"::itemName = \"" <<
self->name() <<
"\";" << std::endl;
130 if (self->hasDefault()) {
132 ss <<
"const " << typeString <<
" " << parentClass <<
"::" <<
self->className() <<
"::defaultValue = " << *defaultValue <<
";" << std::endl;
134 ss <<
"const " << typeString <<
" " << parentClass <<
"::" <<
self->className() <<
"::defaultValue = " <<
self->getDefault() <<
";" << std::endl;
147 template<
typename ParserItemType ,
typename DeckItemType ,
typename ValueType>
149 std::shared_ptr<DeckItemType> deckItem = std::make_shared<DeckItemType>(
self->name() ,
self->scalar() );
151 if (self->sizeType() ==
ALL) {
152 while (rawRecord->size() > 0) {
153 std::string token = rawRecord->pop_front();
155 std::string countString;
156 std::string valueString;
157 if (
isStarToken(token, countString, valueString)) {
158 StarToken st(token, countString, valueString);
162 value = readValueToken<ValueType>(st.
valueString());
163 deckItem->push_backMultiple( value , st.
count());
165 value =
self->getDefault();
166 for (
size_t i=0; i < st.
count(); i++)
167 deckItem->push_backDefault( value );
170 ValueType value = readValueToken<ValueType>(token);
171 deckItem->push_back(value);
175 if (rawRecord->size() == 0) {
177 if (self->hasDefault()) {
179 deckItem->push_backDefault( self->getDefault() );
183 deckItem->push_backDummyDefault();
188 std::string token = rawRecord->pop_front();
189 std::string countString;
190 std::string valueString;
191 if (
isStarToken(token, countString, valueString)) {
192 StarToken st(token, countString, valueString);
195 if (self->hasDefault())
196 deckItem->push_backDefault( self->getDefault() );
198 deckItem->push_backDummyDefault();
200 deckItem->push_back(readValueToken<ValueType>(st.
valueString()));
205 std::string singleRepetition;
209 singleRepetition =
"1*";
211 for (
size_t i=0; i < st.
count() - 1; i++)
212 rawRecord->push_front(singleRepetition);
214 ValueType value = readValueToken<ValueType>(token);
215 deckItem->push_back(value);
virtual void inlineClass(std::ostream &, const std::string &indent) const =0
const std::string & valueString() const
Definition: StarToken.hpp:119
std::shared_ptr< DeckItem > DeckItemPtr
Definition: DeckItem.hpp:126
virtual const std::string & getDimension(size_t index) const
Definition: StarToken.hpp:83
virtual std::string createCode() const =0
void setDescription(std::string helpText)
std::shared_ptr< ParserItem > ParserItemPtr
Definition: ParserItem.hpp:103
virtual bool equal(const ParserItem &other) const =0
bool parserRawItemEqual(const ParserItem &other) const
Definition: ParserItem.hpp:68
virtual size_t numDimensions() const
virtual std::string inlineClassInit(const std::string &parentClass) const =0
std::shared_ptr< const ParserItem > ParserItemConstPtr
Definition: ParserItem.hpp:102
size_t count() const
Definition: StarToken.hpp:99
const std::string & name() const
void ParserItemInlineClassDeclaration(const ParserItemType *self, std::ostream &os, const std::string &indent, const std::string &typeString)
Definition: ParserItem.hpp:108
Definition: JsonObject.hpp:31
ParserItemSizeEnum
Definition: ParserEnums.hpp:37
std::string ParserItemInlineClassInit(const ParserItemType *self, const std::string &parentClass, const std::string &typeString, const std::string *defaultValue=NULL)
Definition: ParserItem.hpp:122
bool isStarToken(const std::string &token, std::string &countString, std::string &valueString)
Definition: ParserItem.hpp:39
bool hasValue() const
Definition: StarToken.hpp:103
Definition: ParserEnums.hpp:38
std::string getDescription() const
ParserItemSizeEnum sizeType() const
virtual DeckItemPtr scan(RawRecordPtr rawRecord) const =0
bool m_defaultSet
Definition: ParserItem.hpp:94
virtual bool hasDimension() const
virtual ~ParserItem()
Definition: ParserItem.hpp:61
std::shared_ptr< RawRecord > RawRecordPtr
Definition: RawRecord.hpp:64
const std::string className() const
virtual void push_backDimension(const std::string &dimension)
DeckItemPtr ParserItemScan(const ParserItemType *self, RawRecordPtr rawRecord)
Definition: ParserItem.hpp:148
ParserItem(const std::string &itemName)