YARP
Yet Another Robot Platform
Triple.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef YARP_SERVERSQL_IMPL_TRIPLE_H
8#define YARP_SERVERSQL_IMPL_TRIPLE_H
9
10#include <string>
11#include <yarp/conf/compiler.h>
12
13
14namespace yarp::serversql::impl {
15
22class Triple
23{
24public:
25 std::string ns;
26 std::string name;
27 std::string value;
28 bool hasNs;
29 bool hasName;
31
32
34 {
35 reset();
36 }
37
38 Triple(const Triple& alt)
39 {
40 hasNs = alt.hasNs;
41 hasName = alt.hasName;
42 hasValue = alt.hasValue;
43 ns = alt.ns;
44 name = alt.name;
45 value = alt.value;
46 }
47
48 void reset()
49 {
50 hasNs = hasName = hasValue = false;
51 ns = name = value = "";
52 }
53
54 void split(const std::string& str)
55 {
56 hasNs = hasName = hasValue = false;
57 ns = name = value = "";
58 size_t start = 0;
59 size_t stop = std::string::npos;
60 size_t ins = str.find(':');
61 if (ins!=std::string::npos) {
62 ns = str.substr(0,ins);
63 start = ins+1;
64 hasNs = true;
65 }
66 size_t ine = str.find('=',start);
67 if (ine!=std::string::npos) {
68 value = str.substr(ine+1,std::string::npos);
69 stop = ine;
70 hasValue = true;
71 }
72 name = str.substr(start,stop-start);
73 hasName = true;
74 }
75
76 const char* getNs()
77 {
78 if (!hasNs) {
79 return nullptr;
80 }
81 return ns.c_str();
82 }
83
84 const char* getName()
85 {
86 if (!hasName) {
87 return nullptr;
88 }
89 return name.c_str();
90 }
91
92 const char* getValue()
93 {
94 if (!hasValue) {
95 return nullptr;
96 }
97 return value.c_str();
98 }
99
100 std::string toString() const
101 {
102 std::string r = "";
103 if (hasName) {
104 r = name;
105 }
106 if (hasValue) {
107 r += "=";
108 r += value;
109 }
110 if (hasNs) {
111 r = std::string(ns) + ":" + r;
112 }
113 return r;
114 }
115
116 void setNsNameValue(const char* ns, const char* name, const char* value)
117 {
119 hasNs = true;
120 this->ns = ns;
121 }
122
123 void setNameValue(const char* name, const char* value)
124 {
125 reset();
126 hasName = true;
127 this->name = name;
128 hasValue = true;
129 this->value = value;
130 }
131};
132
133} // namespace yarp::serversql::impl
134
135
136#endif // YARP_SERVERSQL_IMPL_TRIPLE_H
The basic unit of data the name server works with.
Definition: Triple.h:23
const char * getValue()
Definition: Triple.h:92
void split(const std::string &str)
Definition: Triple.h:54
const char * getName()
Definition: Triple.h:84
void setNsNameValue(const char *ns, const char *name, const char *value)
Definition: Triple.h:116
const char * getNs()
Definition: Triple.h:76
Triple(const Triple &alt)
Definition: Triple.h:38
std::string toString() const
Definition: Triple.h:100
void setNameValue(const char *name, const char *value)
Definition: Triple.h:123