Add missing #include for some headers
[wave300.git] / tools / shared / aux_utils.h
blobc4651f1b90c425e54d473f1c310e05ae83648569
1 /******************************************************************************
3 Copyright (c) 2012
4 Lantiq Deutschland GmbH
6 For licensing information, see the file 'LICENSE' in the root folder of
7 this software module.
9 ******************************************************************************/
10 //$Id: aux_utils.h 5847 2009-01-21 16:09:27Z antonn $
11 #ifndef _AUX_UTILS_H_INCLUDED_
12 #define _AUX_UTILS_H_INCLUDED_
14 #include <ctype.h>
16 #if defined(WIN32)
17 #pragma warning(push,3)
18 #pragma warning(disable:4242)
19 #endif
21 #include <string>
22 #include <vector>
23 #include <sstream>
24 #include <algorithm>
25 #include <stdexcept>
27 #if defined(WIN32)
28 #pragma warning(pop)
29 #endif
31 using namespace std;
33 //GCC has a bug related to use of toupper/tolower
34 //in transform.
35 //See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11108
36 //This is a workaround for the bug.
37 static int toupper_gcc_workaround(int c)
38 {return toupper(c);}
39 static int tolower_gcc_workaround(int c)
40 {return tolower(c);}
42 inline string strToUpper(string str)
44 std::transform(str.begin(), str.end(), str.begin(), toupper_gcc_workaround);
45 return str;
48 inline string strToLower(string str)
50 std::transform(str.begin(), str.end(), str.begin(), tolower_gcc_workaround);
51 return str;
54 inline int stringToint( const string& str )
56 std::istringstream s( str );
57 int ret(0);
58 s >> ret;
60 return (s.rdstate() & std::ios::failbit) ? 0 : ret;
63 inline string intTostring( int value )
65 std::ostringstream s;
66 s << value;
67 return s.str();
70 inline string GetFileSystemPathSeparator()
72 #ifdef WIN32
73 return string("\\");
74 #elif defined(LINUX)
75 return string("/");
76 #else
77 #error Unknown operating system
78 #endif
81 class CStrTokenizer
83 public:
84 class iterator
86 friend class CStrTokenizer;
87 public:
88 iterator( const iterator& other )
89 : m_tokenizer(other.m_tokenizer)
90 , m_token(other.m_token)
91 , m_pos(other.m_pos)
93 const string& get() const
94 { return m_token; }
95 iterator& operator = (const iterator& other);
96 iterator& operator ++();
97 operator bool() const;
98 private:
99 iterator(
100 const CStrTokenizer& tokenizer,
101 const string& separator,
102 size_t position );
103 mutable string m_separator;
104 const CStrTokenizer& m_tokenizer;
105 string m_token;
106 size_t m_pos;
108 friend class iterator;
109 CStrTokenizer( const string& str )
110 : m_string(str)
112 iterator begin( const string& separator ) const
114 return iterator( *this, separator, 0);
116 private:
117 bool operator != (const CStrTokenizer& other) const
119 return this != &other;
121 string m_string;
124 void GetDirectoryContents(const string& strDir, string strFileMask,
125 vector<string>& Result, bool fFilesOnly);
127 string GetCurrDir();
129 class exc_basic : public exception
131 public:
132 virtual ~exc_basic() throw() {
135 virtual const char *what() const throw() {
136 return m_str.c_str();
139 protected:
140 string m_str;
143 class exc_assert : public exc_basic
145 public:
146 exc_assert (const char* str,
147 const char *fname = NULL,
148 int str_no = 0) {
149 ostringstream ss;
150 ss << "Assertion failed : " << str;
151 if (fname) {
152 ss << fname << " : ";
154 if (str_no) {
155 ss << str_no << " : ";
157 m_str = ss.str();
161 #define EXC_ASSERT(expr) \
163 if (!(expr)) { \
164 throw exc_assert(#expr, __FILE__, __LINE__); \
168 #endif //_AUX_UTILS_H_INCLUDED_