Add infos into target window
[ryzomcore.git] / ryzom / server / src / pd_lib / pds_common.h
blob755b3e2a1ace5b87dbd4b69849d91130e3e77bdb
1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifndef RY_PDS_COMMON_H
18 #define RY_PDS_COMMON_H
20 #include <nel/misc/types_nl.h>
21 #include <nel/misc/i_xml.h>
22 #include <vector>
24 #include <nel/misc/log.h>
27 // pd_lib Includes
29 #include "pd_lib.h"
33 /**
34 * Task Event Listener
36 class ITaskEventListener
38 public:
40 /// Called when RBS task was done successfully
41 virtual void taskSuccessful(void* arg) = 0;
43 /// Called when RBS task has failed
44 virtual void taskFailed(void* arg) = 0;
50 class CLocatePath
52 public:
54 /// Constructor
55 CLocatePath() : Pos(0) {}
57 /// End of path?
58 bool end() const
60 return Pos >= FullPath.size();
63 struct CLocateAttributeNode
65 /// The name of the attribute to locate
66 std::string Name;
68 /// Is this node an array?
69 bool Array;
71 /// Is this node a set?
72 bool Set;
74 /// Key, for array and set
75 std::string Key;
78 /// Get current node
79 CLocateAttributeNode& node()
81 return FullPath[Pos];
84 /// Step to next
85 bool next()
87 ++Pos;
88 return !end();
91 typedef std::vector<CLocateAttributeNode> TLocatePath;
93 /// Full path to value
94 TLocatePath FullPath;
96 /// Current pos in path
97 uint Pos;
105 /// 'for' loop through xml children
106 #define FOREACH_CHILD(node, parent, type) for (node=CIXml::getFirstChildNode(parent, #type);\
107 node!=NULL;\
108 node=CIXml::getNextChildNode(node, #type))
114 * Utility functions.
118 * getProperty()
119 * Store node property propName into result
120 * Returns true iff the property appears in the node (but won't tell if property was of the matching type)
122 template<typename T>
123 bool getProperty(xmlNodePtr node, const char* propName, T &result)
125 std::string res;
126 if (!NLMISC::CIXml::getPropertyString(res, node, propName))
128 nlwarning("Couldn't get property '%s' in xml node", propName);
129 return false;
131 NLMISC::fromString(res, result);
132 return true;
136 * getProperty()
137 * Store node property propName into result, and if property not present in node use defaultValue instead
138 * Returns true iff the property appears in the node (but won't tell if property was of the matching type)
140 template<typename T>
141 bool getProperty(xmlNodePtr node, const char* propName, T &result, const T &defaultValue, bool quiet = true)
143 std::string res;
144 if (!NLMISC::CIXml::getPropertyString(res, node, propName))
146 if (!quiet)
147 nlwarning("Couldn't get property '%s' in xml node, use '%s' value instead", propName, NLMISC::toString(defaultValue).c_str());
148 result = defaultValue;
149 return false;
151 NLMISC::fromString(res, result);
152 return true;
158 #endif //RY_PDS_COMMON_H