RSC  0.17.1
langutils.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of RSC project
4  *
5  * Copyright (C) 2010 by Johannes Wienke <jwienke at techfak dot uni-bielefeld dot de>
6  *
7  * This file may be licensed under the terms of the
8  * GNU Lesser General Public License Version 3 (the ``LGPL''),
9  * or (at your option) any later version.
10  *
11  * Software distributed under the License is distributed
12  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
13  * express or implied. See the LGPL for the specific language
14  * governing rights and limitations.
15  *
16  * You should have received a copy of the LGPL along with this
17  * program. If not, go to http://www.gnu.org/licenses/lgpl.html
18  * or write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  * The development of this software was supported by:
22  * CoR-Lab, Research Institute for Cognition and Robotics
23  * Bielefeld University
24  *
25  * ============================================================ */
26 
29 #pragma once
30 
31 #include <string>
32 
33 #include <boost/cstdint.hpp>
34 #include <boost/shared_ptr.hpp>
35 
36 #include "rsc/rscexports.h"
37 
38 namespace rsc {
39 namespace misc {
40 
49 class RSC_EXPORT NullDeleter {
50 public:
51 
57  void operator()(void* ignored) const;
58 
59 };
60 
72 template<class ParentType>
74 public:
75  ParentSharedPtrDeleter(boost::shared_ptr<ParentType> parent) :
76  parent(parent) {
77  }
78 
79  void operator()(void const *) {
80  parent.reset();
81  }
82 
83 private:
84  boost::shared_ptr<ParentType> parent;
85 };
86 
92 RSC_EXPORT boost::uint64_t currentTimeMillis();
93 
99 RSC_EXPORT boost::uint64_t currentTimeMicros();
100 
106 RSC_EXPORT char randAlnumChar();
107 
114 RSC_EXPORT std::string randAlnumStr(const std::string::size_type& length);
115 
116 #ifdef __GNUC__
117 #define GCC_VERSION (__GNUC__ * 10000 \
118  + __GNUC_MINOR__ * 100 \
119  + __GNUC_PATCHLEVEL__)
120 #endif
121 
138 #ifdef __GNUC__
139 #if GCC_VERSION > 40500
140 #define DEPRECATED_MSG(func, msg) func __attribute__ ((deprecated (#msg)))
141 #else
142 #define DEPRECATED_MSG(func, msg) func __attribute__ ((deprecated))
143 #endif
144 #elif defined(_MSC_VER)
145 #define DEPRECATED_MSG(func, msg) __declspec(deprecated(#msg)) func
146 #else
147 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
148 #define DEPRECATED_MSG(func, msg) func
149 #endif
150 
168 #define DEPRECATED(fun) DEPRECATED_MSG(fun, "Use of deprecated construct.")
169 
182 #ifdef __GNUC__
183 #if GCC_VERSION > 40500
184 #define DEPRECATED_CLASS(msg) __attribute__ ((deprecated (#msg)))
185 #else
186 #define DEPRECATED_CLASS(msg) __attribute__ ((deprecated))
187 #endif
188 #elif defined(_MSC_VER)
189 #define DEPRECATED_CLASS(msg) __declspec(deprecated(#msg))
190 #else
191 #pragma message("WARNING: You need to implement DEPRECATED_CLASS for this compiler")
192 #define DEPRECATED_CLASS(msg)
193 #endif
194 
195 // provide static asserts that only issue a warning
196 // adapted from: http://stackoverflow.com/a/8990275/283649
197 
198 #define PP_CAT(x,y) PP_CAT1(x,y)
199 #define PP_CAT1(x,y) x##y
200 
201 namespace detail {
202 
203 struct true_type {
204 };
205 struct false_type {
206 };
207 template<int test> struct converter: public true_type {
208 };
209 template<> struct converter<0> : public false_type {
210 };
211 
212 }
213 
227 #define STATIC_ASSERT_WARN(cond, msg) \
228 struct PP_CAT(static_warning,__LINE__) { \
229  DEPRECATED_MSG(void _(::rsc::misc::detail::false_type const& ),msg) {}; \
230  void _(::rsc::misc::detail::true_type const& ) {}; \
231  PP_CAT(static_warning,__LINE__)() {_(::rsc::misc::detail::converter<(cond)>());} \
232 }
233 
248 #define STATIC_ASSERT_WARN_TEMPLATE(token, cond, msg) \
249  STATIC_ASSERT_WARN(cond, msg) PP_CAT(PP_CAT(_localvar_, token),__LINE__)
250 
251 }
252 }
253 
A deleter object that can be used with boost::shared_ptr that doesn&#39;t release any memory...
Definition: langutils.h:49
std::string randAlnumStr(const std::string::size_type &length)
Generates a random alpha-numeric string with fixed length.
Definition: langutils.cpp:108
ParentSharedPtrDeleter(boost::shared_ptr< ParentType > parent)
Definition: langutils.h:75
boost::uint64_t currentTimeMillis()
Returns the current system time as milliseconds.
Definition: langutils.cpp:64
void operator()(void const *)
Definition: langutils.h:79
char randAlnumChar()
Generates a random alpha-numeric character.
Definition: langutils.cpp:100
boost::uint64_t currentTimeMicros()
Returns the current system time as microseconds.
Definition: langutils.cpp:82
boost::shared_ptr< ParentType > parent
Definition: langutils.h:84
A deleter for boost::shared_ptr which enables to use a pointer in a shared_ptr, which is not a shared...
Definition: langutils.h:73