voxelTerrain
 All Classes Functions Variables Typedefs Enumerations Pages
string.hpp
1 #ifndef BLUB_STRING_HPP
2 #define BLUB_STRING_HPP
3 
4 #include "blub/core/globals.hpp"
5 #include "blub/serialization/access.hpp"
6 
7 #include <string>
8 
9 #include <boost/lexical_cast.hpp>
10 #include <boost/serialization/binary_object.hpp>
11 
12 #ifdef BLUB_USE_SOCI
13 # include <soci-backend.h>
14 # include <type-conversion.h>
15 #endif
16 
17 
18 namespace blub
19 {
20 
21 
22 class string : public std::string
23 {
24 public:
25  typedef std::string t_base;
26 
27  string()
28  : t_base()
29  {;}
30  string(const char* str)
31  : t_base(str)
32  {}
33  string(const char* str, uint32 len)
34  : t_base(str, len)
35  {}
36  string(const t_base& str)
37  : t_base(str)
38  {}
39  string(const byteArray& array);
40 
41  template<typename numberType>
42  static string number(const numberType& n)
43  {
44  return boost::lexical_cast<string>(n);
45  }
46 
47 protected:
48  BLUB_SERIALIZATION_ACCESS
49  template<typename Archive>
50  void serialize(Archive & readWrite, const unsigned int version)
51  {
52  (void)version;
53 
54  readWrite & BOOST_SERIALIZATION_BASE_OBJECT_NVP(t_base);
55  }
56 };
57 
58 
59 std::size_t hash_value(const blub::string& value);
60 
61 
62 }
63 
64 
65 std::ostream& operator << (std::ostream& ostr, const blub::string& toCast);
66 
67 #ifdef BLUB_USE_SOCI
68 
69 
70 namespace soci
71 {
72 
73 
74 template <>
75 struct type_conversion<blub::string>
76 {
77  typedef std::string base_type;
78 
79  static void from_base(std::string i, soci::indicator ind, blub::string & mi)
80  {
81  if (ind == i_null)
82  {
83  throw soci_error("Null value not allowed for this type");
84  }
85 
86  mi = static_cast<blub::string>(i);
87  }
88 
89  static void to_base(const blub::string & mi, std::string & i, indicator & ind)
90  {
91  i = static_cast<std::string>(mi);
92  ind = i_ok;
93  }
94 };
95 
96 
97 }
98 
99 
100 #endif
101 
102 #endif // BLUB_STRING_HPP
Definition: string.hpp:22
Definition: byteArray.hpp:17
Definition: deadlineTimer.hpp:10
Definition: array.hpp:18