20 #include "UniSetTypes.h"
21 #include "Configuration.h"
34 template<
typename T,
typename... _Args>
35 std::shared_ptr<T> make_object(
const std::string& idname,
const std::string& secname, _Args&& ... __args )
41 throw uniset::SystemError(
"(make_object<" +
string(
typeid(T).name()) +
">): Not found ID for '" + idname +
"'");
43 auto xml = conf->getConfXML();
44 std::string s( (secname.empty() ? idname : secname) );
45 xmlNode* cnode = conf->findNode(xml->getFirstNode(), s, idname);
48 throw uniset::SystemError(
"(make_object<" +
string(
typeid(T).name()) +
">): Not found xmlnode <" + s +
" name='" + idname +
"' ... >");
50 std::shared_ptr<T> obj = std::make_shared<T>(id, cnode, std::forward<_Args>(__args)...);
60 template<
typename T,
typename... _Args>
61 std::shared_ptr<T> make_object_x( xmlNode* root,
const std::string& secname, _Args&& ... __args )
64 auto xml = conf->getConfXML();
65 xmlNode* cnode = conf->findNode(root, secname,
"");
68 throw uniset::SystemError(
"(make_object_x<" +
string(
typeid(T).name()) +
">): Not found xmlnode <" + secname +
" ... >");
70 string idname = conf->getProp(cnode,
"name");
74 throw uniset::SystemError(
"(make_object_x<" +
string(
typeid(T).name()) +
">): Not found ID for '" + idname +
"'");
76 return std::make_shared<T>(id, cnode, std::forward<_Args>(__args)...);
86 template<
typename T,
typename M,
typename... _Args>
87 std::shared_ptr<T> make_child_object( M* m,
const std::string& idname,
const std::string& secname, _Args&& ... __args )
91 m->log()->info() << m->getName() <<
"(" << __FUNCTION__ <<
"): " <<
"create " << idname <<
"..." << std::endl;
92 auto o = uniset::make_object<T>(idname, secname, std::forward<_Args>(__args)...);
94 m->logAgregator()->add(o->logAgregator());
99 m->log()->crit() << m->getName() <<
"(" << __FUNCTION__ <<
"): " <<
"(create " << idname <<
"): " << ex << std::endl;
105 template<
typename T,
typename M,
typename... _Args>
106 std::shared_ptr<T> make_child_object_x( M* m, xmlNode* root,
const std::string& secname, _Args&& ... __args )
110 auto o = uniset::make_object_x<T>(root, secname, std::forward<_Args>(__args)...);
112 m->logAgregator()->add(o->logAgregator());
117 m->log()->crit() << m->getName() <<
"(" << __FUNCTION__ <<
"): " <<
"(create " << string(
typeid(T).name()) <<
"): " << ex << std::endl;
124 #endif // UHelpers_H_
Definition: CallbackTimer.h:29
Definition: Exceptions.h:44
std::shared_ptr< Configuration > uniset_conf() noexcept
Definition: Configuration.cc:89
const ObjectId DefaultObjectId
Definition: UniSetTypes.h:56
Definition: Exceptions.h:89
long ObjectId
Definition: UniSetTypes_i.idl:30