Motorcortex Core  version: 2.7.6
ps_paramtype.h
1 /*
2  * Developer : Alexey Zakharov (alexey.zakharov@vectioneer.com)
3  * All rights reserved. Copyright (c) 2020 VECTIONEER.
4  */
5 
6 #ifndef MOTORCORTEX_CORE_PS_PARAMTYPE_H
7 #define MOTORCORTEX_CORE_PS_PARAMTYPE_H
8 
9 #include <string>
10 #include <limits>
11 #include <utility>
12 
13 namespace mcx {
14 
15 namespace parameter_server {
16 
18 public:
19 
20  static constexpr uint32_t FULL_LENGTH{std::numeric_limits<uint32_t>::max()};
21 
22  enum Type {
23  ABSOLUTE,
24  RELATIVE
25  };
26 
27  ParameterPath() = default;
28 
29  ParameterPath(const char* path) : path_{path} {
30  }
31 
32  ParameterPath(std::string path) : path_{std::move(path)} {
33  }
34 
35  ParameterPath(std::string path, Type type) : path_{std::move(path)}, type_{type} {
36  }
37 
38  ParameterPath(std::string path, uint32_t element_offset) : path_{std::move(path)},
39  element_offset_{element_offset}, length_{1} {
40  }
41 
42  ParameterPath(std::string path, Type type, uint32_t element_offset) : path_{std::move(path)}, type_{type},
43  element_offset_{element_offset}, length_{1} {
44  }
45 
46  ParameterPath(std::string path, uint32_t element_offset, uint32_t length) : path_{std::move(path)},
47  element_offset_{element_offset},
48  length_{length} {
49  }
50 
51  ParameterPath(std::string path, Type type,
52  uint32_t element_offset, uint32_t length) : path_{std::move(path)}, type_{type},
53  element_offset_{element_offset}, length_{length} {
54  }
55 
56 
57  uint32_t getElementOffset() const {
58  return element_offset_;
59  }
60 
61  uint32_t getLength() const {
62  return length_;
63  }
64 
65  const char* getPath() const {
66  return path_.c_str();
67  }
68 
69  bool isRelative() const {
70  return type_ == Type::RELATIVE;
71  }
72 
73 private:
74 
75  std::string path_;
76  Type type_{Type::ABSOLUTE};
77  uint32_t element_offset_{0};
78  uint32_t length_{FULL_LENGTH};
79 };
80 
81 } // namespace parameter_server
82 
83 } // namespace mcx
84 
85 #endif //MOTORCORTEX_CORE_PS_PARAMTYPE_H
mcx::parameter_server::ParameterPath
Definition: ps_paramtype.h:17