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::os {
15 
16 // We need a constexpr for efficient switching.
27 constexpr yarp::conf::vocab32_t createVocab32(char a, char b = 0, char c = 0, char d = 0)
28 {
29  return (static_cast<yarp::conf::vocab32_t>(a)) +
30  (static_cast<yarp::conf::vocab32_t>(b) << 8) +
31  (static_cast<yarp::conf::vocab32_t>(c) << 16) +
32  (static_cast<yarp::conf::vocab32_t>(d) << 24);
33 }
34 
35 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5
36 YARP_DEPRECATED_MSG("Use createVocab32() instead")
37 constexpr yarp::conf::vocab32_t createVocab(char a, char b = 0, char c = 0, char d = 0)
38 {
39  return createVocab32(a, b, c, d);
40 }
41 #endif // YARP_NO_DEPRECATED
42 
64 namespace Vocab32 {
65 
73 YARP_os_API NetInt32 encode(const std::string& str);
74 
80 YARP_os_API std::string decode(NetInt32 code);
81 
82 } // namespace Vocab32
83 
84 #ifndef YARP_NO_DEPRECATED // Since YARP 3.5
85 // Swig is not happy of having two methods with the same name in
86 // different namespaces
87 #ifndef SWIG
88 namespace Vocab {
89 
90 YARP_DEPRECATED_MSG("Use yarp::os::Vocab32::encode instead")
91 inline NetInt32 encode(const std::string& str)
92 {
93  return Vocab32::encode(str);
94 }
95 
96 YARP_DEPRECATED_MSG("Use yarp::os::Vocab32::decode instead")
97 inline std::string decode(NetInt32 code)
98 {
99  return Vocab32::decode(code);
100 }
101 
102 } // namespace Vocab
103 #endif // SWIG
104 #endif // YARP_NO_DEPRECATED
105 
106 } // namespace yarp::os
107 
108 
109 #ifndef YARP_NO_DEPRECATED // since YARP 3.1.0
110 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
111 constexpr int32_t VOCAB(char a, char b, char c, char d)
112 {
113  return yarp::os::createVocab32(a, b, c, d);
114 }
115 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
116 constexpr int32_t VOCAB4(char a, char b, char c, char d)
117 {
118  return yarp::os::createVocab32(a, b, c, d);
119 }
120 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
121 constexpr int32_t VOCAB3(char a, char b, char c)
122 {
123  return yarp::os::createVocab32(a, b, c, 0);
124 }
125 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
126 constexpr int32_t VOCAB2(char a, char b)
127 {
128  return yarp::os::createVocab32(a, b, 0, 0);
129 }
130 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
131 constexpr int32_t VOCAB1(char a)
132 {
133  return yarp::os::createVocab32(a, 0, 0, 0);
134 }
135 #endif // YARP_NO_DEPRECATED
136 
137 #endif // YARP_OS_VOCAB_H
constexpr int32_t VOCAB2(char a, char b)
Definition: Vocab.h:126
constexpr int32_t VOCAB3(char a, char b, char c)
Definition: Vocab.h:121
constexpr int32_t VOCAB(char a, char b, char c, char d)
Definition: Vocab.h:111
constexpr int32_t VOCAB1(char a)
Definition: Vocab.h:131
constexpr int32_t VOCAB4(char a, char b, char c, char d)
Definition: Vocab.h:116
#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:91
std::string decode(NetInt32 code)
Definition: Vocab.h:97
An interface to the operating system, including Port based communication.
std::int32_t NetInt32
Definition of the NetInt32 type.
Definition: NetInt32.h:29
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Definition: Vocab.h:37
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:27
The main, catch-all namespace for YARP.
Definition: dirs.h:16
#define YARP_os_API
Definition: api.h:18