2007-08-17 00:36:07 +02:00
|
|
|
/*
|
2007-08-23 17:52:33 +02:00
|
|
|
UTIL.hpp - collection of small helper functions used "everywhere"
|
2007-08-17 00:36:07 +02:00
|
|
|
|
|
|
|
|
Copyright (C) CinelerraCV
|
|
|
|
|
2007, Christian Thaeter <ct@pipapo.org>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of the
|
|
|
|
|
License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef UTIL_HPP_
|
|
|
|
|
#define UTIL_HPP_
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace util
|
|
|
|
|
{
|
|
|
|
|
using std::string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** a family of util functions providing a "no value whatsoever" test */
|
2007-08-23 17:52:33 +02:00
|
|
|
inline bool isnil(const string& val)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return 0 == val.length();
|
|
|
|
|
}
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
inline bool isnil(const string* pval)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return !pval || 0 == pval->length();
|
|
|
|
|
}
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
inline bool isnil(const char* pval)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return !pval || 0 == std::strlen(pval);
|
|
|
|
|
}
|
2007-08-17 00:36:07 +02:00
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
/** cut a numeric value to be >=0 */
|
|
|
|
|
template <typename NUM>
|
|
|
|
|
inline NUM noneg (NUM val)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return (0<val? val : 0);
|
|
|
|
|
}
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
/** shortcut for containment test on a map */
|
|
|
|
|
template <typename MAP>
|
|
|
|
|
inline bool contains (MAP& map, typename MAP::key_type& key)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return map.find(key) != map.end();
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
/** shortcut for operating on all elements of a container.
|
|
|
|
|
* Isn't this already defined somewhere? It's so obvious..
|
|
|
|
|
*/
|
|
|
|
|
template <typename Container, typename Oper>
|
|
|
|
|
inline Oper
|
|
|
|
|
for_each (Container& c, Oper& doIt)
|
2007-08-26 19:14:39 +02:00
|
|
|
{
|
|
|
|
|
return std::for_each (c.begin(),c.end(), doIt);
|
|
|
|
|
}
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
|
2007-08-17 00:36:07 +02:00
|
|
|
} // namespace util
|
2007-08-23 17:52:33 +02:00
|
|
|
|
|
|
|
|
/* some common macro definitions */
|
|
|
|
|
|
|
|
|
|
/** this macro wraps its parameter into a cstring literal */
|
|
|
|
|
#define STRINGIFY(TOKEN) __STRNGFY(TOKEN)
|
|
|
|
|
#define __STRNGFY(TOKEN) #TOKEN
|
|
|
|
|
|
|
|
|
|
|
2007-08-17 00:36:07 +02:00
|
|
|
#endif /*UTIL_HPP_*/
|