Fixed up ScalarSequenceParser
Also, Vector3Parser and ColorParser. Go me!
This commit is contained in:
parent
1f51ba2dd7
commit
a393a8fb5a
3 changed files with 74 additions and 62 deletions
|
@ -196,7 +196,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
/**
|
/**
|
||||||
* UtilityParsers handle small reusable bits of YAML. Their constructors take a
|
* 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.
|
* C++11 lambda, which will be called back with the result of the parsed data.
|
||||||
|
@ -208,13 +207,13 @@ struct UtilityParser
|
||||||
typedef std::function<void(T)> CallbackFunction;
|
typedef std::function<void(T)> CallbackFunction;
|
||||||
|
|
||||||
UtilityParser(Scene& scene,
|
UtilityParser(Scene& scene,
|
||||||
ParserStack& parsers)
|
Parser::Stack& parsers)
|
||||||
: Parser(scene, parsers),
|
: Parser(scene, parsers),
|
||||||
mCallback()
|
mCallback()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
UtilityParser(Scene& scene,
|
UtilityParser(Scene& scene,
|
||||||
ParserStack& parsers,
|
Parser::Stack& parsers,
|
||||||
CallbackFunction callback)
|
CallbackFunction callback)
|
||||||
: Parser(scene, parsers),
|
: Parser(scene, parsers),
|
||||||
mCallback(callback)
|
mCallback(callback)
|
||||||
|
@ -243,17 +242,6 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Defines traits for the ParseScalar function. In particular, defines the
|
|
||||||
* format strings for supported scalar types.
|
|
||||||
*/
|
|
||||||
template<typename T>
|
|
||||||
struct ScalarParserTraits
|
|
||||||
{
|
|
||||||
static const char* fmt;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse a YAML scalar value into a native datatype.
|
* Parse a YAML scalar value into a native datatype.
|
||||||
*
|
*
|
||||||
|
@ -269,7 +257,6 @@ ParseScalar(const std::string& scalar,
|
||||||
std::stringstream s(scalar);
|
std::stringstream s(scalar);
|
||||||
return bool(s >> value);
|
return bool(s >> value);
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
} /* namespace charles */
|
} /* namespace charles */
|
||||||
|
|
|
@ -8,10 +8,49 @@
|
||||||
#include "yaml/vectorParser.hh"
|
#include "yaml/vectorParser.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool
|
||||||
|
ScalarSequenceParser<T>::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<Type>(value, scalarValue)) {
|
||||||
|
assert(false);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
mVector.push_back(scalarValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
bool
|
||||||
|
ScalarSequenceParser<T>::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,
|
Vector3Parser::Vector3Parser(Scene& scene,
|
||||||
ParserStack& parsers,
|
Parser::Stack& parsers,
|
||||||
CallbackFunction onDone)
|
CallbackFunction onDone)
|
||||||
: ScalarSequenceParser(scene, parsers)
|
: ScalarSequenceParser(scene, parsers)
|
||||||
{
|
{
|
||||||
|
@ -26,12 +65,8 @@ Vector3Parser::Vector3Parser(Scene& scene,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector3Parser::~Vector3Parser()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
|
|
||||||
ColorParser::ColorParser(Scene& scene,
|
ColorParser::ColorParser(Scene& scene,
|
||||||
ParserStack& parsers,
|
Parser::Stack& parsers,
|
||||||
CallbackFunction onDone)
|
CallbackFunction onDone)
|
||||||
: ScalarSequenceParser(scene, parsers)
|
: ScalarSequenceParser(scene, parsers)
|
||||||
{
|
{
|
||||||
|
@ -50,8 +85,5 @@ ColorParser::ColorParser(Scene& scene,
|
||||||
SetCallback(onSeqDone);
|
SetCallback(onSeqDone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ColorParser::~ColorParser()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
|
} /* namespace charles */
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
#include "parsers.hh"
|
#include "parsers.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace charles {
|
||||||
namespace yaml {
|
namespace yaml {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,28 +32,32 @@ struct ScalarSequenceParser
|
||||||
typedef typename UtilityParser<VectorType>::CallbackFunction CallbackFunction;
|
typedef typename UtilityParser<VectorType>::CallbackFunction CallbackFunction;
|
||||||
|
|
||||||
ScalarSequenceParser(Scene& scene,
|
ScalarSequenceParser(Scene& scene,
|
||||||
ParserStack& parsers)
|
Parser::Stack& parsers)
|
||||||
: UtilityParser<VectorType>(scene, parsers),
|
: UtilityParser<VectorType>(scene, parsers),
|
||||||
mVector()
|
mVector()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/** Constructor */
|
/** Constructor */
|
||||||
ScalarSequenceParser(Scene& scene,
|
ScalarSequenceParser(Scene& scene,
|
||||||
ParserStack& parsers,
|
Parser::Stack& parsers,
|
||||||
CallbackFunction callback)
|
CallbackFunction callback)
|
||||||
: UtilityParser<VectorType>(scene, parsers, callback),
|
: UtilityParser<VectorType>(scene, parsers, callback),
|
||||||
mVector()
|
mVector()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
/**
|
bool HandleScalar(const std::string& anchor,
|
||||||
* Handle a YAML parser event.
|
const std::string& tag,
|
||||||
*
|
const std::string& value,
|
||||||
* @param [in] event The parser event
|
bool plainImplicit,
|
||||||
*/
|
bool quotedImplicit,
|
||||||
void
|
Parser::ScalarStyle style,
|
||||||
HandleEvent(yaml_event_t& event)
|
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
|
* XXX: Need to prefix with this-> for some reason. Maybe the
|
||||||
* compiler can't figure out the type properly?
|
* compiler can't figure out the type properly?
|
||||||
|
@ -61,20 +66,8 @@ struct ScalarSequenceParser
|
||||||
|
|
||||||
/* We have a completed vector. Notify the caller. */
|
/* We have a completed vector. Notify the caller. */
|
||||||
this->Notify(mVector);
|
this->Notify(mVector);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.type != YAML_SCALAR_EVENT) {
|
return true;
|
||||||
assert(event.type != YAML_SCALAR_EVENT);
|
|
||||||
}
|
|
||||||
|
|
||||||
Type value;
|
|
||||||
std::string valueString((char*)event.data.scalar.value,
|
|
||||||
event.data.scalar.length);
|
|
||||||
if (!ParseScalar<Type>(valueString, value)) {
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
mVector.push_back(value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -87,8 +80,7 @@ struct Vector3Parser
|
||||||
{
|
{
|
||||||
typedef std::function<void(Vector3)> CallbackFunction;
|
typedef std::function<void(Vector3)> CallbackFunction;
|
||||||
|
|
||||||
Vector3Parser(Scene& scene, ParserStack& parsers, CallbackFunction onDone);
|
Vector3Parser(Scene& scene, Parser::Stack& parsers, CallbackFunction onDone);
|
||||||
~Vector3Parser();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,10 +89,11 @@ struct ColorParser
|
||||||
{
|
{
|
||||||
typedef std::function<void(Color)> CallbackFunction;
|
typedef std::function<void(Color)> CallbackFunction;
|
||||||
|
|
||||||
ColorParser(Scene& scene, ParserStack& parsers, CallbackFunction onDone);
|
ColorParser(Scene& scene, Parser::Stack& parsers, CallbackFunction onDone);
|
||||||
~ColorParser();
|
~ColorParser();
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace yaml */
|
} /* namespace yaml */
|
||||||
|
} /* namespace charles */
|
||||||
|
|
||||||
#endif /* __YAML_VECTOR_PARSER_HH__ */
|
#endif /* __YAML_VECTOR_PARSER_HH__ */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue