diff --git a/src/yaml/parsers.hh b/src/yaml/parsers.hh index affe578..bc62afe 100644 --- a/src/yaml/parsers.hh +++ b/src/yaml/parsers.hh @@ -196,7 +196,6 @@ private: }; -#if 0 /** * UtilityParsers handle small reusable bits of YAML. Their constructors take a * C++11 lambda, which will be called back with the result of the parsed data. @@ -205,16 +204,16 @@ template struct UtilityParser : public Parser { - typedef std::function CallbackFunction; + typedef std::function CallbackFunction; UtilityParser(Scene& scene, - ParserStack& parsers) + Parser::Stack& parsers) : Parser(scene, parsers), mCallback() { } UtilityParser(Scene& scene, - ParserStack& parsers, + Parser::Stack& parsers, CallbackFunction callback) : Parser(scene, parsers), mCallback(callback) @@ -243,17 +242,6 @@ private: }; -/** - * Defines traits for the ParseScalar function. In particular, defines the - * format strings for supported scalar types. - */ -template -struct ScalarParserTraits -{ - static const char* fmt; -}; - - /** * Parse a YAML scalar value into a native datatype. * @@ -269,7 +257,6 @@ ParseScalar(const std::string& scalar, std::stringstream s(scalar); return bool(s >> value); } -#endif } /* namespace yaml */ } /* namespace charles */ diff --git a/src/yaml/vectorParser.cc b/src/yaml/vectorParser.cc index 5409f97..71eeee5 100644 --- a/src/yaml/vectorParser.cc +++ b/src/yaml/vectorParser.cc @@ -8,10 +8,49 @@ #include "yaml/vectorParser.hh" +namespace charles { namespace yaml { +template +bool +ScalarSequenceParser::HandleScalar(const std::string& anchor, + const std::string& tag, + const std::string& value, + bool plainImplicit, + bool quotedImplicit, + Parser::ScalarStyle style, + const Parser::Mark& startMark, + const Parser::Mark& endMark) +{ + Type scalarValue; + if (!ParseScalar(value, scalarValue)) { + assert(false); + return false; + } + mVector.push_back(scalarValue); + return true; +} + + +template +bool +ScalarSequenceParser::HandleSequenceEnd(const Parser::Mark& startMark, + const Parser::Mark& endMark) +{ + /* + * XXX: Need to prefix with this-> for some reason. Maybe the compiler can't + * figure out the type properly? + */ + this->SetDone(true); + + /* We have a completed vector. Notify the caller. */ + this->Notify(mVector); + + return true; +} + Vector3Parser::Vector3Parser(Scene& scene, - ParserStack& parsers, + Parser::Stack& parsers, CallbackFunction onDone) : ScalarSequenceParser(scene, parsers) { @@ -26,12 +65,8 @@ Vector3Parser::Vector3Parser(Scene& scene, } -Vector3Parser::~Vector3Parser() -{ } - - ColorParser::ColorParser(Scene& scene, - ParserStack& parsers, + Parser::Stack& parsers, CallbackFunction onDone) : ScalarSequenceParser(scene, parsers) { @@ -50,8 +85,5 @@ ColorParser::ColorParser(Scene& scene, SetCallback(onSeqDone); } - -ColorParser::~ColorParser() -{ } - } /* namespace yaml */ +} /* namespace charles */ diff --git a/src/yaml/vectorParser.hh b/src/yaml/vectorParser.hh index 2eb1bb5..7a79411 100644 --- a/src/yaml/vectorParser.hh +++ b/src/yaml/vectorParser.hh @@ -16,6 +16,7 @@ #include "parsers.hh" +namespace charles { namespace yaml { /** @@ -24,57 +25,49 @@ namespace yaml { */ template struct ScalarSequenceParser - : public UtilityParser > + : public UtilityParser> { typedef T Type; typedef std::vector VectorType; typedef typename UtilityParser::CallbackFunction CallbackFunction; ScalarSequenceParser(Scene& scene, - ParserStack& parsers) + Parser::Stack& parsers) : UtilityParser(scene, parsers), mVector() { } /** Constructor */ ScalarSequenceParser(Scene& scene, - ParserStack& parsers, + Parser::Stack& parsers, CallbackFunction callback) : UtilityParser(scene, parsers, callback), mVector() { } - /** - * Handle a YAML parser event. - * - * @param [in] event The parser event - */ - void - HandleEvent(yaml_event_t& event) + bool HandleScalar(const std::string& anchor, + const std::string& tag, + const std::string& value, + bool plainImplicit, + bool quotedImplicit, + Parser::ScalarStyle style, + const Parser::Mark& startMark, + const Parser::Mark& endMark); + + bool + HandleSequenceEnd(const Parser::Mark& startMark, + const Parser::Mark& endMark) { - if (event.type == YAML_SEQUENCE_END_EVENT) { - /* - * XXX: Need to prefix with this-> for some reason. Maybe the - * compiler can't figure out the type properly? - */ - this->SetDone(true); + /* + * XXX: Need to prefix with this-> for some reason. Maybe the + * compiler can't figure out the type properly? + */ + this->SetDone(true); - /* We have a completed vector. Notify the caller. */ - this->Notify(mVector); - return; - } + /* We have a completed vector. Notify the caller. */ + this->Notify(mVector); - if (event.type != YAML_SCALAR_EVENT) { - assert(event.type != YAML_SCALAR_EVENT); - } - - Type value; - std::string valueString((char*)event.data.scalar.value, - event.data.scalar.length); - if (!ParseScalar(valueString, value)) { - assert(false); - } - mVector.push_back(value); + return true; } private: @@ -85,22 +78,22 @@ private: struct Vector3Parser : ScalarSequenceParser { - typedef std::function CallbackFunction; + typedef std::function CallbackFunction; - Vector3Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); - ~Vector3Parser(); + Vector3Parser(Scene& scene, Parser::Stack& parsers, CallbackFunction onDone); }; struct ColorParser : ScalarSequenceParser { - typedef std::function CallbackFunction; + typedef std::function CallbackFunction; - ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone); + ColorParser(Scene& scene, Parser::Stack& parsers, CallbackFunction onDone); ~ColorParser(); }; } /* namespace yaml */ +} /* namespace charles */ #endif /* __YAML_VECTOR_PARSER_HH__ */