a bunch of stuff

This commit is contained in:
Eduardo Bart
2011-05-11 19:16:11 -03:00
parent 42c1ae090c
commit c6753747fb
63 changed files with 663 additions and 375 deletions

View File

@@ -67,16 +67,6 @@ private:
RGBA color;
};
inline void operator>>(const YAML::Node& node, Color& color)
{
int r, g, b, a;
node[0] >> r;
node[1] >> g;
node[2] >> b;
node[3] >> a;
color.setRGBA(r,g,b,a);
}
inline std::ostream& operator<<(std::ostream& out, const Color& color)
{
out << "Color(" << (int)color.r() << ","

View File

@@ -77,13 +77,6 @@ public:
typedef TPoint<int> Point;
typedef TPoint<float> PointF;
template <class T>
inline void operator>>(const YAML::Node& node, TPoint<T>& point)
{
node[0] >> point.x;
node[1] >> point.y;
}
template <class T>
inline std::ostream& operator<<(std::ostream& out, const TPoint<T>& point)
{

View File

@@ -299,17 +299,6 @@ private:
typedef TRect<int> Rect;
typedef TRect<float> RectF;
template <class T>
inline void operator>>(const YAML::Node& node, TRect<T>& rect)
{
T x, y, width, height;
node[0] >> x;
node[1] >> y;
node[2] >> width;
node[3] >> height;
rect.setRect(x, y, width, height);
}
template <class T>
inline std::ostream& operator<<(std::ostream& out, const TRect<T>& rect)
{

View File

@@ -111,15 +111,6 @@ private:
typedef TSize<int> Size;
typedef TSize<float> SizeF;
template <class T>
inline void operator>>(const YAML::Node& node, TSize<T>& size)
{
T w, h;
node[0] >> w;
node[1] >> h;
size.setSize(w, h);
}
template <class T>
inline std::ostream& operator<<(std::ostream& out, const TSize<T>& size)
{

View File

@@ -22,4 +22,28 @@
*/
#include <util/util.h>
#include <cstdio>
#include <boost/algorithm/string.hpp>
AlignmentFlag parseAlignment(std::string aligment)
{
boost::to_lower(aligment);
boost::erase_all(aligment, " ");
if(aligment == "topleft")
return AlignTopLeft;
else if(aligment == "topright")
return AlignTopRight;
else if(aligment == "bottomleft")
return AlignBottomLeft;
else if(aligment == "bottomright")
return AlignBottomRight;
else if(aligment == "left")
return AlignLeftCenter;
else if(aligment == "right")
return AlignRightCenter;
else if(aligment == "top")
return AlignTopCenter;
else if(aligment == "bottom")
return AlignBottomCenter;
else
return AlignCenter;
}

View File

@@ -28,13 +28,14 @@
#include <util/logger.h>
#include <boost/lexical_cast.hpp>
#include <boost/format.hpp>
#include <constants.h>
/// Easy/fast writting formater
#define f(a, b) (boost::format(a) % b).str()
// Easy/fast writing formater
#define fmt(a, b) (boost::format(a) % b).str()
/// Convert any data type through boost::lexical_cast
template<class R, class T>
R convertType(T t)
template<class R, class T>
R convert_cast(T t)
{
R ret = R();
try {
@@ -45,4 +46,7 @@ R convertType(T t)
return ret;
}
AlignmentFlag parseAlignment(std::string aligment);
#endif // UTIL_H

122
src/framework/util/yaml.h Normal file
View File

@@ -0,0 +1,122 @@
/* The MIT License
*
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef YAML_H
#define YAML_H
#include <prerequisites.h>
#include <yaml-cpp/yaml.h>
inline void operator>>(const YAML::Node& node, Color& color)
{
int r, g, b, a;
node[0] >> r;
node[1] >> g;
node[2] >> b;
node[3] >> a;
color.setRGBA(r,g,b,a);
}
template <class T>
inline void operator>>(const YAML::Node& node, TPoint<T>& point)
{
node[0] >> point.x;
node[1] >> point.y;
}
template <class T>
inline void operator>>(const YAML::Node& node, TRect<T>& rect)
{
T x, y, width, height;
node[0] >> x;
node[1] >> y;
node[2] >> width;
node[3] >> height;
rect.setRect(x, y, width, height);
}
template <class T>
inline void operator>>(const YAML::Node& node, TSize<T>& size)
{
T w, h;
node[0] >> w;
node[1] >> h;
size.setSize(w, h);
}
template<class T>
inline T yamlRead(const YAML::Node& node)
{
return node.Read<T>();
}
template<class T>
inline T yamlRead(const YAML::Node& node, const char *name)
{
T value;
node[name] >> value;
return value;
}
template<class T>
inline T yamlRead(const YAML::Node& node, const char *name, const T& defaultValue)
{
T value = defaultValue;
if(node.FindValue(name))
node[name] >> value;
return value;
}
inline bool yamlHasValue(const YAML::Node& node, const char *name)
{
return node.FindValue(name) != NULL;
}
inline std::string yamlErrorDesc(const YAML::Node& node, const std::string& error)
{
return YAML::Exception(node.GetMark(), error.c_str()).what();
}
inline void yamlThrowError(const YAML::Node& node, const std::string& error)
{
throw YAML::Exception(node.GetMark(), error.c_str());
}
template<class A, class B>
inline std::map<A,B> yamlReadMap(const YAML::Node& node, const char *name)
{
std::map<A,B> map;
if(const YAML::Node* mapNode = node.FindValue(name)) {
for(auto it = mapNode->begin(); it != mapNode->end(); ++it) {
A a;
B b;
it.first() >> a;
it.second() >> b;
map[a] = b;
}
}
return map;
}
#endif // YAML_H