YARP
Yet Another Robot Platform
Vocab.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_OS_VOCAB_H
8 #define YARP_OS_VOCAB_H
9 
10 #include <yarp/os/NetInt32.h>
11 
12 #include <string>
13 
14 namespace yarp {
15 namespace os {
16 
17 // We need a constexpr for efficient switching.
28 constexpr yarp::conf::vocab32_t createVocab32(char a, char b = 0, char c = 0, char d = 0)
29 {
30  return (static_cast<yarp::conf::vocab32_t>(a)) +
31  (static_cast<yarp::conf::vocab32_t>(b) << 8) +
32  (static_cast<yarp::conf::vocab32_t>(c) << 16) +
33  (static_cast<yarp::conf::vocab32_t>(d) << 24);
34 }
35 
36 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5
37 YARP_DEPRECATED_MSG("Use createVocab32() instead")
38 constexpr yarp::conf::vocab32_t createVocab(char a, char b = 0, char c = 0, char d = 0)
39 {
40  return createVocab32(a, b, c, d);
41 }
42 #endif // YARP_NO_DEPRECATED
43 
65 namespace Vocab32 {
66 
74 YARP_os_API NetInt32 encode(const std::string& str);
75 
81 YARP_os_API std::string decode(NetInt32 code);
82 
83 } // namespace Vocab32
84 
85 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5
86 // Swig is not happy of having two methods with the same name in
87 // different namespaces
88 #ifndef SWIG
89 namespace Vocab {
90 
91 YARP_DEPRECATED_MSG("Use yarp::os::Vocab32::encode instead")
92 inline NetInt32 encode(const std::string& str)
93 {
94  return Vocab32::encode(str);
95 }
96 
97 YARP_DEPRECATED_MSG("Use yarp::os::Vocab32::decode instead")
98 inline std::string decode(NetInt32 code)
99 {
100  return Vocab32::decode(code);
101 }
102 
103 } // namespace Vocab
104 #endif // SWIG
105 #endif // YARP_NO_DEPRECATED
106 
107 } // namespace os
108 } // namespace yarp
109 
110 
111 
112 
113 #ifndef YARP_NO_DEPRECATED // since YARP 3.1.0
114 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
115 constexpr int32_t VOCAB(char a, char b, char c, char d)
116 {
117  return yarp::os::createVocab32(a, b, c, d);
118 }
119 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
120 constexpr int32_t VOCAB4(char a, char b, char c, char d)
121 {
122  return yarp::os::createVocab32(a, b, c, d);
123 }
124 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
125 constexpr int32_t VOCAB3(char a, char b, char c)
126 {
127  return yarp::os::createVocab32(a, b, c, 0);
128 }
129 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
130 constexpr int32_t VOCAB2(char a, char b)
131 {
132  return yarp::os::createVocab32(a, b, 0, 0);
133 }
134 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
135 constexpr int32_t VOCAB1(char a)
136 {
137  return yarp::os::createVocab32(a, 0, 0, 0);
138 }
139 #endif // YARP_NO_DEPRECATED
140 
141 #endif // YARP_OS_VOCAB_H
constexpr int32_t VOCAB2(char a, char b)
Definition: Vocab.h:130
constexpr int32_t VOCAB3(char a, char b, char c)
Definition: Vocab.h:125
constexpr int32_t VOCAB(char a, char b, char c, char d)
Definition: Vocab.h:115
constexpr int32_t VOCAB1(char a)
Definition: Vocab.h:135
constexpr int32_t VOCAB4(char a, char b, char c, char d)
Definition: Vocab.h:120
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2885
std::int32_t vocab32_t
Definition: numeric.h:78
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.cpp:11
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition: Vocab.cpp:33
NetInt32 encode(const std::string &str)
Definition: Vocab.h:92
std::string decode(NetInt32 code)
Definition: Vocab.h:98
std::int32_t NetInt32
Definition of the NetInt32 type.
Definition: NetInt32.h:30
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Definition: Vocab.h:38
constexpr yarp::conf::vocab32_t createVocab32(char a, char b=0, char c=0, char d=0)
Create a vocab from chars.
Definition: Vocab.h:28
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18