28 #ifndef __pinocchio_parser_lua_tables_hpp____ 29 #define __pinocchio_parser_lua_tables_hpp____ 51 std::string string_value;
53 bool operator<(
const LuaKey & rhs )
const {
54 if (type == String && rhs.type == Integer) {
56 }
else if (type == Integer && rhs.type == String) {
58 }
else if (type == Integer && rhs.type == Integer) {
59 return int_value < rhs.int_value;
62 return string_value < rhs.string_value;
65 LuaKey (
const char* key_value) :
68 string_value (key_value) { }
71 int_value (key_value),
75 inline std::ostream & operator<<(std::ostream & output,
const LuaKey & key) {
76 if (key.type == LuaKey::Integer)
77 output << key.int_value <<
"(int)";
79 output << key.string_value <<
"(string)";
94 child_node.luaTable = luaTable;
95 child_node.parent =
this;
96 child_node.key =
LuaKey (child_str);
103 child_node.luaTable = luaTable;
104 child_node.parent =
this;
105 child_node.key =
LuaKey (child_index);
109 bool stackQueryValue();
111 void stackCreateValue();
116 std::vector<LuaKey> getKeyStack();
117 std::string keyStackToString();
122 std::vector<LuaKey> keys();
126 template <
typename T>
127 void set (
const T & value);
128 template <
typename T>
129 T getDefault (
const T & default_value);
131 template <
typename T>
134 std::cerr <<
"Error: could not find value " << keyStackToString() <<
"." << std::endl;
137 return getDefault (T());
141 template <
typename T>
142 void operator=(
const T & value) {
145 template <
typename T>
149 template <
typename T>
150 bool operator==(T value) {
151 return value == get<T>();
153 template <
typename T>
154 bool operator!=(T value) {
155 return value != get<T>();
166 return value == (T) node;
170 return value != (T) node;
173 template<>
bool LuaTableNode::getDefault<bool>(
const bool & default_value);
174 template<>
double LuaTableNode::getDefault<double>(
const double & default_value);
175 template<>
float LuaTableNode::getDefault<float>(
const float & default_value);
176 template<> std::string LuaTableNode::getDefault<std::string>(
const std::string & default_value);
178 template<>
void LuaTableNode::set<bool>(
const bool & value);
179 template<>
void LuaTableNode::set<float>(
const float & value);
180 template<>
void LuaTableNode::set<double>(
const double & value);
181 template<>
void LuaTableNode::set<std::string>(
const std::string & value);
187 deleteLuaState (
false)
194 root_node.key =
LuaKey (key);
195 root_node.parent = NULL;
196 root_node.luaTable =
this;
202 root_node.key =
LuaKey (key);
203 root_node.parent = NULL;
204 root_node.luaTable =
this;
209 void addSearchPath (
const char* path);
210 std::string serialize ();
211 std::string orderedSerialize ();
213 static LuaTable fromFile (
const char *_filename);
214 static LuaTable fromLuaExpression (
const char* lua_expr);
215 static LuaTable fromLuaState (lua_State *L);
217 std::string filename;
223 #endif // ifndef __pinocchio_parser_lua_tables_hpp____