OpenZWave Library  1.5.0
Utils.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // Utils.h
4 //
5 // Miscellaneous helper functions
6 //
7 // Copyright (c) 2010 Mal Lansell <openzwave@lansell.org>
8 //
9 // SOFTWARE NOTICE AND LICENSE
10 //
11 // This file is part of OpenZWave.
12 //
13 // OpenZWave is free software: you can redistribute it and/or modify
14 // it under the terms of the GNU Lesser General Public License as published
15 // by the Free Software Foundation, either version 3 of the License,
16 // or (at your option) any later version.
17 //
18 // OpenZWave is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU Lesser General Public License for more details.
22 //
23 // You should have received a copy of the GNU Lesser General Public License
24 // along with OpenZWave. If not, see <http://www.gnu.org/licenses/>.
25 //
26 //-----------------------------------------------------------------------------
27 
28 #ifndef _Utils_H
29 #define _Utils_H
30 
31 #include "platform/Mutex.h"
32 #include "platform/Log.h"
33 
34 #include <string>
35 #include <locale>
36 #include <algorithm>
37 #include <sstream>
38 #include <vector>
39 
40 namespace OpenZWave
41 {
48  string ToUpper( string const& _str );
49 
56  string ToLower( string const& _str );
57 
65  void split (std::vector<std::string>& lst, const std::string& input, const std::string& separators, bool remove_empty = true);
66 
72  std::string &trim ( std::string &s );
73 
74 
75  void PrintHex(std::string prefix, uint8_t const *data, uint32 const length);
76  string PktToString(uint8 const *data, uint32 const length);
77 
78  struct LockGuard
79  {
80  LockGuard(Mutex* mutex) : _ref(mutex)
81  {
82  //std::cout << "Locking" << std::endl;
83  _ref->Lock();
84  };
85 
87  {
88 #if 0
89  if (_ref->IsSignalled())
90  std::cout << "Already Unlocked" << std::endl;
91  else
92  std::cout << "Unlocking" << std::endl;
93 #endif
94  if (!_ref->IsSignalled())
95  _ref->Unlock();
96  }
97  void Unlock()
98  {
99 // std::cout << "Unlocking" << std::endl;
100  _ref->Unlock();
101  }
102  private:
103  LockGuard(const LockGuard&);
104  LockGuard& operator = ( LockGuard const& );
105 
106 
107  Mutex* _ref;
108  };
109 
110  string ozwdirname(string);
111 
112  string intToString( int x );
113 
114 
115 
116 } // namespace OpenZWave
117 
118 #endif
119 
120 
121 
void Unlock()
Definition: Utils.h:97
Definition: Bitfield.h:34
void Unlock()
Definition: Mutex.cpp:81
string ozwdirname(string)
Definition: Utils.cpp:148
string intToString(int x)
Definition: Utils.cpp:158
Definition: Utils.h:78
bool Lock(bool const _bWait=true)
Definition: Mutex.cpp:69
string PktToString(uint8 const *data, uint32 const length)
Definition: Utils.cpp:122
string ToLower(string const &_str)
Definition: Utils.cpp:53
unsigned int uint32
Definition: Defs.h:96
void PrintHex(std::string prefix, uint8_t const *data, uint32 const length)
Definition: Utils.cpp:118
LockGuard(Mutex *mutex)
Definition: Utils.h:80
void split(std::vector< std::string > &lst, const std::string &input, const std::string &separators, bool remove_empty=true)
Definition: Utils.cpp:95
std::string & trim(std::string &s)
Definition: Utils.cpp:68
~LockGuard()
Definition: Utils.h:86
string ToUpper(string const &_str)
Definition: Utils.cpp:39
Implements a platform-independent mutex–for serializing access to a shared resource.
Definition: Mutex.h:40
virtual bool IsSignalled()
Definition: Mutex.cpp:98
unsigned char uint8
Definition: Defs.h:90