Friendly LWM2M client
ItemOp.h
Go to the documentation of this file.
1 #ifndef WPP_ITEM_OPERATION_H
2 #define WPP_ITEM_OPERATION_H
3 
4 #include <vector>
5 
6 #include "WppTypes.h"
7 
8 namespace wpp {
9 
24 struct ItemOp {
25 public:
29  enum TYPE: uint8_t {
30  NONE = 0,
31  READ = 1,
32  WRITE = 2,
33  EXECUTE = 4,
34  DISCOVER = 8,
35  CREATE = 16,
36  DELETE = 32,
37  };
38 
39 public:
45  ItemOp(uint8_t flags = TYPE::NONE): _flags(flags) {}
46 
53  inline bool isSupported(TYPE type) const { return _flags & type; };
54 
63  inline bool isCompatible(const ItemOp& operation) const { return (_flags & operation._flags) == _flags; };
64 
70  inline bool isRead() const { return _flags & READ; }
71 
77  inline bool isWrite() const { return _flags & WRITE; }
78 
84  inline bool isExecute() const { return _flags & EXECUTE; }
85 
91  inline bool isDiscover() const { return _flags & DISCOVER; }
92 
98  inline bool isCreate() const { return _flags & CREATE; }
99 
105  inline bool isDelete() const { return _flags & DELETE; }
106 
112  inline uint8_t getFlags() const { return _flags; }
113 
119  inline std::vector<TYPE> asVector() const {
120  uint32_t flags = _flags;
121  std::vector<TYPE> operations;
122  for (size_t i = 1; i != 0x100; i <<= 1) {
123  if (flags & i) operations.push_back((TYPE)i);
124  }
125  return operations;
126  }
127 
128 private:
129  uint8_t _flags;
130 };
131 
132 } // namespace wpp
133 
134 #endif //WPP_ITEM_OPERATION_H
The WppConnection class represents a connection interface for the Wpp library.
Definition: WppClient.cpp:14
The ItemOp struct represents the operations that can be performed on a instance/resource.
Definition: ItemOp.h:24
std::vector< TYPE > asVector() const
Converts the flags into a vector of operation types.
Definition: ItemOp.h:119
bool isSupported(TYPE type) const
Checks if a specific operation is supported.
Definition: ItemOp.h:53
bool isCreate() const
Checks if the operation is of type CREATE.
Definition: ItemOp.h:98
bool isExecute() const
Checks if the ItemOp object represents an execute operation.
Definition: ItemOp.h:84
bool isDiscover() const
Checks if the ItemOp object represents a discover operation.
Definition: ItemOp.h:91
bool isCompatible(const ItemOp &operation) const
Checks if the ItemOp object is compatible with another ItemOp object.
Definition: ItemOp.h:63
bool isWrite() const
Checks if the ItemOp object represents a write operation.
Definition: ItemOp.h:77
bool isRead() const
Checks if the ItemOp object represents a read operation.
Definition: ItemOp.h:70
ItemOp(uint8_t flags=TYPE::NONE)
Constructs a ItemOp object with the specified flags.
Definition: ItemOp.h:45
uint8_t getFlags() const
Retrieves the flags representing the operations.
Definition: ItemOp.h:112
bool isDelete() const
Checks if the operation is of type DELETE.
Definition: ItemOp.h:105
TYPE
Enum representing the different types of operations.
Definition: ItemOp.h:29
@ DELETE
Definition: ItemOp.h:36
@ EXECUTE
Definition: ItemOp.h:33
@ DISCOVER
Definition: ItemOp.h:34
@ CREATE
Definition: ItemOp.h:35