28 #ifndef __TERRALIB_COMMON_INTERNAL_STLUTILS_H
29 #define __TERRALIB_COMMON_INTERNAL_STLUTILS_H
51 template<
class T>
inline void FreeContents(
const std::vector<T*>& v)
53 std::size_t size = v.size();
55 for(std::size_t i = 0; i < size; ++i)
68 for(
typename std::list<T*>::const_iterator it = l.begin(); it != l.end(); ++it)
79 template<
class K,
class V>
inline void FreeContents(std::map<K, V*>& m)
81 typename std::map<K, V*>::const_iterator it = m.begin();
82 typename std::map<K, V*>::const_iterator itend = m.end();
98 template<
class V,
class C>
inline void FreeContents(std::set<V*, C>& m)
100 typename std::set<V*, C>::const_iterator it = m.begin();
101 typename std::set<V*, C>::const_iterator itend = m.end();
133 template<
class T>
inline void Free(std::vector<T*>* v)
138 std::size_t size = v->size();
140 for(std::size_t i = 0; i < size; ++i)
151 inline void Free(
char** carray)
153 for(
char** aux = carray; *aux; ++aux)
165 template<
class T>
inline void Free(T** a, std::size_t s)
167 for(std::size_t i = 0; i < s; ++i)
181 template<
class K,
class V>
inline V*
GetPValue(
const std::map<K, V*>& m,
const K& k)
183 typename std::map<K, V*>::const_iterator it = m.find(k);
199 template<
class K,
class C>
inline K*
GetPValue(
const std::set<K*, C>& m, K* k)
201 typename std::set<K*, C>::const_iterator it = m.find(k);
219 template<
class K,
class V>
inline V**
GetPPValue(std::map<K, V*>& m,
const K& k)
221 typename std::map<K, V*>::iterator it = m.find(k);
224 return &(it->second);
239 template<
class T,
class T1>
inline void Clone(
const std::vector<T*>& src, std::vector<T1*>& dst)
241 std::size_t size = src.size();
245 for (std::size_t i = 0; i < size; ++i)
247 if (src[i] ==
nullptr)
249 dst.push_back(
nullptr);
253 dst.push_back(
static_cast<T1*
>(src[i]->clone()));
266 template<
class T>
inline void Copy(
const std::vector<T*>& src, std::vector<T*>& dst)
268 std::size_t size = src.size();
272 for(std::size_t i = 0; i < size; ++i)
273 dst.push_back(
new T(*src[i]));
276 template<
class T>
inline bool Contains(
const std::vector<T>& src,
const T& value)
278 return std::find(src.begin(), src.end(), value) != src.end();
281 inline std::string
GetCurrentTime(
const std::string& format =
"%d.%m.%Y %H:%M:%S")
283 std::time_t now = std::time(NULL);
284 std::tm* ptm = std::localtime(&now);
289 std::strftime(buffer, 32, format.c_str(), ptm);
291 std::string time(buffer);
V * GetPValue(const std::map< K, V * > &m, const K &k)
It finds for a given key in the map and returns a pointer if something is found or NULL otherwise.
std::string GetCurrentTime(const std::string &format="%d.%m.%Y %H:%M:%S")
void Clone(const std::vector< T * > &src, std::vector< T1 * > &dst)
This function can be applied to a vector of pointers.
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map.
void Copy(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers. It will copy element by element through its cop...
V ** GetPPValue(std::map< K, V * > &m, const K &k)
It finds for a given key in the map and returns a pointer if something is found or NULL otherwise.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
bool Contains(const std::vector< T > &src, const T &value)