simple_string.hpp
Go to the documentation of this file.
1 #ifndef SIMPLE_STRING_HPP
2 #define SIMPLE_STRING_HPP
3 
4 #include <string>
5 #include <cstring>
6 
7 namespace SafeAny
8 {
9 // Version of string that uses only two words. Good for small object optimization in linb::any
11 {
12  public:
13  SimpleString(const std::string& str) : SimpleString(str.data(), str.size())
14  {
15  }
16  SimpleString(const char* data) : SimpleString(data, strlen(data))
17  {
18  }
19 
20  SimpleString(const char* data, std::size_t size) : _size(size)
21  {
22  _data = new char[_size + 1];
23  strncpy(_data, data, _size);
24  _data[_size] = '\0';
25  }
26 
27  SimpleString(const SimpleString& other) : SimpleString(other.data(), other.size())
28  {
29  }
30 
32  {
33  if (_data)
34  {
35  delete[] _data;
36  }
37  }
38 
39  std::string toStdString() const
40  {
41  return std::string(_data, _size);
42  }
43 
44  const char* data() const
45  {
46  return _data;
47  }
48 
49  std::size_t size() const
50  {
51  return _size;
52  }
53 
54  private:
55  char* _data;
56  std::size_t _size;
57 };
58 }
59 
60 #endif // SIMPLE_STRING_HPP
SimpleString(const char *data)
SimpleString(const std::string &str)
SimpleString(const char *data, std::size_t size)
SimpleString(const SimpleString &other)
std::string toStdString() const
std::size_t size() const
const char * data() const


behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sat Feb 2 2019 04:01:53