Main Page
Modules
Namespaces
Classes
Files
File List
File Members
include
behaviortree_cpp
blackboard
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
10
class
SimpleString
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
31
~SimpleString
()
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
SafeAny::SimpleString::~SimpleString
~SimpleString()
Definition:
simple_string.hpp:31
SafeAny::SimpleString
Definition:
simple_string.hpp:10
SafeAny::SimpleString::_size
std::size_t _size
Definition:
simple_string.hpp:56
SafeAny
Definition:
convert_impl.hpp:8
SafeAny::SimpleString::SimpleString
SimpleString(const char *data)
Definition:
simple_string.hpp:16
SafeAny::SimpleString::SimpleString
SimpleString(const std::string &str)
Definition:
simple_string.hpp:13
SafeAny::SimpleString::SimpleString
SimpleString(const char *data, std::size_t size)
Definition:
simple_string.hpp:20
SafeAny::SimpleString::SimpleString
SimpleString(const SimpleString &other)
Definition:
simple_string.hpp:27
SafeAny::SimpleString::toStdString
std::string toStdString() const
Definition:
simple_string.hpp:39
SafeAny::SimpleString::size
std::size_t size() const
Definition:
simple_string.hpp:49
SafeAny::SimpleString::_data
char * _data
Definition:
simple_string.hpp:55
SafeAny::SimpleString::data
const char * data() const
Definition:
simple_string.hpp:44
behaviortree_cpp
Author(s): Michele Colledanchise, Davide Faconti
autogenerated on Sun Feb 3 2019 03:14:32