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