improvements

This commit is contained in:
Eduardo Bart 2011-05-21 16:10:07 -03:00
parent f5a15939b2
commit 46485d0d76
5 changed files with 36 additions and 42 deletions

View File

@ -1,10 +0,0 @@
# Try to find yaml-cpp
# YAMLCPP_FOUND - system has yaml-cpp
# YAMLCPP_INCLUDE_DIR - the yaml-cpp include directory
# YAMLCPP_LIBRARY - the yaml-cpp library
FIND_PATH(YAMLCPP_INCLUDE_DIR NAMES yaml.h PATH_SUFFIXES yaml-cpp)
FIND_LIBRARY(YAMLCPP_LIBRARY NAMES libyaml-cpp.a yaml-cpp)
INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR)
MARK_AS_ADVANCED(YAMLCPP_LIBRARY YAMLCPP_INCLUDE_DIR)

View File

@ -1,15 +1,15 @@
window#messageBoxWindow: window#messageBoxWindow
size: [192, 78] size: [192, 78]
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
label#textLabel: label#textLabel
anchors.horizontalCenter: parent.horizontalCenter anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top anchors.top: parent.top
margin.top: 27 margin.top: 27
button#okButton: button#okButton
text: Ok text: Ok
size: [43, 20] size: [43, 20]
anchors.right: parent.right anchors.right: parent.right

View File

@ -102,7 +102,7 @@ bool Font::load(const std::string& file)
// read custom widths // read custom widths
if(doc->hasNode("glyph widths")) { if(doc->hasNode("glyph widths")) {
std::map<int, int> glyphWidths; std::map<int, int> glyphWidths;
(*(doc->at("glyph widths"))) >> glyphWidths; doc->readAt("glyph widths", &glyphWidths);
foreach(const auto& pair, glyphWidths) foreach(const auto& pair, glyphWidths)
m_glyphsSize[pair.first].setWidth(pair.second); m_glyphsSize[pair.first].setWidth(pair.second);
} }

View File

@ -2,7 +2,6 @@
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <boost/tokenizer.hpp> #include <boost/tokenizer.hpp>
#include <boost/lexical_cast.hpp>
namespace FML { namespace FML {

View File

@ -72,7 +72,7 @@ public:
// extracting values operator // extracting values operator
template <typename T> template <typename T>
friend void operator >> (const Node& node, T& value); friend bool operator >> (const Node& node, T& value);
// get nodes // get nodes
Node* at(const std::string& childTag) const; Node* at(const std::string& childTag) const;
@ -85,13 +85,18 @@ public:
// read values // read values
template <typename T> template <typename T>
T read(T def = T()) const { T read(T def = T()) const {
T value = def; T v = def;
*this >> value; *this >> v;
return value; return v;
} }
template <typename T> template <typename T>
T readAt(const std::string childTag, T def = T()) const { bool read(T* v) const {
return (*this >> *v);
}
template <typename T>
T readAt(const std::string& childTag, T def = T()) const {
T v = def; T v = def;
for(NodeList::const_iterator it = m_children.begin(); it != m_children.end(); ++it) { for(NodeList::const_iterator it = m_children.begin(); it != m_children.end(); ++it) {
if((*it)->tag() == childTag) { if((*it)->tag() == childTag) {
@ -102,6 +107,15 @@ public:
return v; return v;
} }
template <typename T>
bool readAt(const std::string& childTag, T* v) const {
for(NodeList::const_iterator it = m_children.begin(); it != m_children.end(); ++it) {
if((*it)->tag() == childTag)
return (*(*it) >> *v);
}
return false;
}
void addNode(Node* node); void addNode(Node* node);
private: private:
@ -118,23 +132,28 @@ private:
// Node operators // Node operators
template <typename T> template <typename T>
void operator >> (const Node& node, T& v) bool operator >> (const Node& node, T& v)
{ {
fml_convert(node.value(), v); return fml_convert(node.value(), v);
} }
template <typename T> template <typename T>
void operator >> (const Node& node, std::vector<T>& v) bool operator >> (const Node& node, std::vector<T>& v)
{ {
bool ret = true;
v.clear(); v.clear();
v.resize(node.size()); v.resize(node.size());
for(unsigned i=0;i<node.size();++i) for(unsigned i=0;i<node.size();++i) {
*node.at(i) >> v[i]; if(!(*node.at(i) >> v[i]))
ret = false;
}
return ret;
} }
template <typename K, typename T> template <typename K, typename T>
void operator >> (const Node& node, std::map<K, T>& m) bool operator >> (const Node& node, std::map<K, T>& m)
{ {
bool ret = true;
m.clear(); m.clear();
for(Node::const_iterator it = node.begin(); it != node.end(); ++it) { for(Node::const_iterator it = node.begin(); it != node.end(); ++it) {
Node* child = (*it); Node* child = (*it);
@ -143,8 +162,10 @@ void operator >> (const Node& node, std::map<K, T>& m)
if(fml_convert<std::string, K>(child->tag(), k)) { if(fml_convert<std::string, K>(child->tag(), k)) {
*child >> v; *child >> v;
m[k] = v; m[k] = v;
ret = false;
} }
} }
return ret;
} }
@ -198,20 +219,4 @@ private:
} // namespace FML { } // namespace FML {
// enable usage with foreach
namespace boost
{
// specialize range_mutable_iterator and range_const_iterator in namespace boost
template<>
struct range_mutable_iterator< FML::Node >
{
typedef FML::Node::iterator type;
};
template<>
struct range_const_iterator< FML::Node >
{
typedef FML::Node::const_iterator type;
};
}
#endif // FML_H #endif // FML_H