Add ScalarMappingParser
This commit is contained in:
parent
7153ec759b
commit
625e3a6f47
3 changed files with 121 additions and 0 deletions
|
@ -8,6 +8,7 @@ Import('env')
|
||||||
files = [
|
files = [
|
||||||
'parsers.cc',
|
'parsers.cc',
|
||||||
'object_parser.cc',
|
'object_parser.cc',
|
||||||
|
'scalarMappingParser.cc',
|
||||||
'scene_parser.cc',
|
'scene_parser.cc',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
76
src/yaml/scalarMappingParser.cc
Normal file
76
src/yaml/scalarMappingParser.cc
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
/* scalarMappingParser.cc
|
||||||
|
* vim: set tw=80:
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Implementation of ScalarMappingParser.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "scalarMappingParser.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace yaml {
|
||||||
|
|
||||||
|
ScalarMappingParser::ScalarMappingParser(Scene& scene,
|
||||||
|
ParserStack& parsers)
|
||||||
|
: Parser(scene, parsers),
|
||||||
|
mShouldExpectKey(true)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
ScalarMappingParser::~ScalarMappingParser()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScalarMappingParser::HandleEvent(yaml_event_t& event)
|
||||||
|
{
|
||||||
|
if (mShouldExpectKey && event.type == YAML_SCALAR_EVENT) {
|
||||||
|
HandleKeyEvent(std::string((char*)event.data.scalar.value,
|
||||||
|
event.data.scalar.length));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HandleValueEvent(event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma mark key/value handling
|
||||||
|
|
||||||
|
void
|
||||||
|
ScalarMappingParser::HandleKeyEvent(const std::string& key)
|
||||||
|
{
|
||||||
|
printf("%s: key = %s\n", __PRETTY_FUNCTION__, key.c_str());
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wunused-parameter"
|
||||||
|
|
||||||
|
void
|
||||||
|
ScalarMappingParser::HandleValueEvent(yaml_event_t& event)
|
||||||
|
{
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
ScalarMappingParser::SetShouldExpectKey(bool shouldExpectKey)
|
||||||
|
{
|
||||||
|
mShouldExpectKey = shouldExpectKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool
|
||||||
|
ScalarMappingParser::GetShouldExpectKey()
|
||||||
|
const
|
||||||
|
{
|
||||||
|
return mShouldExpectKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
} /* namespace yaml */
|
44
src/yaml/scalarMappingParser.hh
Normal file
44
src/yaml/scalarMappingParser.hh
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/* scalarMappingParser.hh
|
||||||
|
* vim: set tw=80:
|
||||||
|
* Eryn Wells <eryn@erynwells.me>
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* Declares a yaml::ScalarMappingParser.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef __YAML_SCALARMAPPINGPARSER_HH__
|
||||||
|
#define __YAML_SCALARMAPPINGPARSER_HH__
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "yaml/parsers.hh"
|
||||||
|
|
||||||
|
|
||||||
|
namespace yaml {
|
||||||
|
|
||||||
|
struct ScalarMappingParser
|
||||||
|
: public Parser
|
||||||
|
{
|
||||||
|
ScalarMappingParser(Scene& scene, ParserStack& parsers);
|
||||||
|
virtual ~ScalarMappingParser();
|
||||||
|
|
||||||
|
void HandleEvent(yaml_event_t& event);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void HandleKeyEvent(const std::string& key);
|
||||||
|
virtual void HandleValueEvent(yaml_event_t& event);
|
||||||
|
|
||||||
|
void SetShouldExpectKey(bool shouldExpectKey);
|
||||||
|
bool GetShouldExpectKey() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** Subclasses set this to `true` when they're finished parsing the value. */
|
||||||
|
bool mShouldExpectKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
} /* namespace yaml */
|
||||||
|
|
||||||
|
#endif /* __YAML_SCALARMAPPINGPARSER_HH__ */
|
Loading…
Add table
Add a link
Reference in a new issue