YARP
Yet Another Robot Platform
Vocab.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2018 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_OS_VOCAB_H
11 #define YARP_OS_VOCAB_H
12 
13 #include <yarp/os/NetInt32.h>
14 
15 #include <string>
16 
17 
40 namespace yarp {
41 namespace os {
42 // We need a constexpr for efficient switching.
43 // Use as, for example, createVocab('s','e','t')
44 constexpr yarp::conf::vocab32_t createVocab(char a, char b = 0, char c = 0, char d = 0)
45 {
46  return ((yarp::conf::vocab32_t)a) +
47  ((yarp::conf::vocab32_t)b << 8) +
48  ((yarp::conf::vocab32_t)c << 16) +
49  ((yarp::conf::vocab32_t)d << 24);
50 }
51 
52 namespace Vocab {
53 
61 YARP_OS_API NetInt32 encode(const std::string& str);
62 
68 YARP_OS_API std::string decode(NetInt32 code);
69 
70 } // namespace Vocab
71 } // namespace os
72 } // namespace yarp
73 
74 #ifndef YARP_NO_DEPRECATED // since YARP 3.1.0
75 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
76 constexpr int32_t VOCAB(char a, char b, char c, char d)
77 {
78  return yarp::os::createVocab(a, b, c, d);
79 }
80 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
81 constexpr int32_t VOCAB4(char a, char b, char c, char d)
82 {
83  return yarp::os::createVocab(a, b, c, d);
84 }
85 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
86 constexpr int32_t VOCAB3(char a, char b, char c)
87 {
88  return yarp::os::createVocab(a, b, c, 0);
89 }
90 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
91 constexpr int32_t VOCAB2(char a, char b)
92 {
93  return yarp::os::createVocab(a, b, 0, 0);
94 }
95 YARP_DEPRECATED_MSG("Use yarp::os::createVocab() instead")
96 constexpr int32_t VOCAB1(char a)
97 {
98  return yarp::os::createVocab(a, 0, 0, 0);
99 }
100 #endif // YARP_NO_DEPRECATED
101 
102 #endif // YARP_OS_VOCAB_H
constexpr int32_t VOCAB4(char a, char b, char c, char d)
Definition: Vocab.h:81
constexpr int32_t VOCAB2(char a, char b)
Definition: Vocab.h:91
#define YARP_OS_API
Definition: api.h:19
std::int32_t vocab32_t
Definition: numeric.h:52
The main, catch-all namespace for YARP.
Definition: numeric.h:47
std::string decode(NetInt32 code)
Convert a vocabulary identifier into a string.
Definition: Vocab.cpp:35
constexpr int32_t VOCAB(char a, char b, char c, char d)
Definition: Vocab.h:76
NetInt32 encode(const std::string &str)
Convert a string into a vocabulary identifier.
Definition: Vocab.cpp:14
std::int32_t NetInt32
Definition of the NetInt32 type.
Definition: NetInt32.h:33
constexpr yarp::conf::vocab32_t createVocab(char a, char b=0, char c=0, char d=0)
Definition: Vocab.h:44
constexpr int32_t VOCAB3(char a, char b, char c)
Definition: Vocab.h:86
constexpr int32_t VOCAB1(char a)
Definition: Vocab.h:96
#define YARP_DEPRECATED_MSG(MSG)
Expands to either the standard [[deprecated]] attribute or a compiler-specific decorator such as __at...
Definition: compiler.h:2838