5 #include <Poco/SharedPtr.h>
7 #include <Poco/Logger.h>
8 #include <Poco/Exception.h>
9 #include <Poco/SingletonHolder.h>
11 #include "util/SAXHelper.h"
12 #include "util/Loggable.h"
18 bool operator() (
const Poco::SharedPtr<T> &a,
19 const Poco::SharedPtr<T> &b)
const
28 typedef std::set<Poco::SharedPtr<T>,
32 const Poco::SharedPtr<T> findById(
const typename T::ID &
id)
const;
34 typename InfoSet::const_iterator begin()
const
36 return infoSet().begin();
39 typename InfoSet::const_iterator end()
const
41 return infoSet().end();
45 bool registerInfo(
const T &info);
47 virtual InfoSet &infoSet();
48 virtual const InfoSet &infoSet()
const;
60 typename InfoProvider<T>::InfoSet &InfoProvider<T>::infoSet()
66 const typename InfoProvider<T>::InfoSet &InfoProvider<T>::infoSet()
const
72 const Poco::SharedPtr<T> InfoProvider<T>::findById(
const typename T::ID &
id)
const
74 Poco::SharedPtr<T> pattern(
new T());
77 auto it = infoSet().find(pattern);
78 if (it == infoSet().end())
85 bool InfoProvider<T>::registerInfo(
const T &info)
87 const Poco::SharedPtr<T> copy(
new T(info));
89 if (infoSet().find(copy) != infoSet().end())
92 infoSet().insert(copy);
102 typename InfoProvider<T>::InfoSet &infoSet()
override;
103 const typename InfoProvider<T>::InfoSet &infoSet()
const override;
106 template <
typename T>
109 throw Poco::NotImplementedException(__func__);
112 template <
typename T>
113 const typename InfoProvider<T>::InfoSet &NullInfoProvider<T>::infoSet()
const
115 throw Poco::NotImplementedException(__func__);
118 template <
typename T>
119 InfoProvider<T> &NullInfoProvider<T>::instance()
121 static Poco::SingletonHolder<NullInfoProvider<T>> singleton;
122 return *singleton.get();
125 template <
typename T>
131 template <
typename SAXHandler>
132 void parseFile(
const std::string &path,
133 const std::string &infoLabel);
136 template <
typename T>
141 template <
typename T>
template <
typename SAXHandler>
142 void XmlInfoProvider<T>::parseFile(
const std::string &path,
143 const std::string &infoLabel)
148 Poco::Path file(path);
151 SAXHelper::parse(file, handler);
153 for (
const auto &info : handler) {
154 this->logger().information(
"register " + infoLabel
156 +
" with ID " + info.id().toString(),
159 if (this->registerInfo(info))
162 this->logger().error(infoLabel +
" " + info.name()
163 +
" with ID " + info.id().toString()
164 +
" is already registered",
Definition: InfoProvider.h:17
Definition: InfoProvider.h:126
Definition: InfoProvider.h:97
Definition: InfoProvider.h:26
Definition: Loggable.h:19