PLCnext API Documentation  22.9.0.33
StandardAttributes.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 #include "Arp/Plc/Commons/Meta/StandardAttribute.hpp"
9 #include <bitset>
10 
11 namespace Arp { namespace Plc { namespace Commons { namespace Meta
12 {
13 
16 {
17 public: // typedefs
18 
19 public: // construction/destruction
23  StandardAttributes(const StandardAttributes& arg) = default;
31  ~StandardAttributes(void) = default;
32 
33 public: // static properties
34  static const StandardAttributes None;
35 
36 public: // operators
38  operator StandardAttribute(void)const;
39 
42  size_t GetCacheSize(void)const;
43 
44 public: // setter/getter operations
48  bool IsSet(StandardAttribute flag)const;
49 
53  bool IsAnySet(StandardAttribute flags)const;
54 
57  size_t CountSet() const;
58 
61  StandardAttribute GetValue(void)const;
62 
63 private: // fields
65 };
66 
68 // inline methods of class StandardAttributes
69 
71  : value(value)
72 {
73 }
74 
75 inline StandardAttributes::operator StandardAttribute()const
76 {
77  return this->value;
78 }
79 
81 {
82  using U = std::underlying_type<StandardAttribute>::type;
83  return (static_cast<U>(flag) & static_cast<U>(this->value)) == static_cast<U>(flag);
84 }
85 
87 {
88  using U = std::underlying_type<StandardAttribute>::type;
89  return (static_cast<U>(flags) & static_cast<U>(this->value)) != 0;
90 }
91 
92 inline size_t StandardAttributes::CountSet() const
93 {
94  using U = std::underlying_type<StandardAttribute>::type;
95  std::bitset<sizeof(U) * 8> bits(static_cast<U>(this->value));
96  return bits.count();
97 }
98 
100 {
101  return this->value;
102 }
103 
104 inline size_t StandardAttributes::GetCacheSize(void)const
105 {
106  return sizeof(this->value);
107 }
108 
109 }}}} // end of namespace Arp::Plc::Meta
Collection of StandardAttribute flags
Definition: StandardAttributes.hpp:16
bool IsSet(StandardAttribute flag) const
Check if a flag is set
Definition: StandardAttributes.hpp:80
StandardAttributes(StandardAttributes &&arg)=default
Move constructor.
bool IsAnySet(StandardAttribute flags) const
Check if any of the given flags is set
Definition: StandardAttributes.hpp:86
StandardAttribute GetValue(void) const
Gets the underlying value
Definition: StandardAttributes.hpp:99
StandardAttributes & operator=(const StandardAttributes &arg)=default
Copy assignment operator.
StandardAttributes(StandardAttribute value=StandardAttribute::None)
Constructs a StandardAttributes instance.
Definition: StandardAttributes.hpp:70
StandardAttributes(const StandardAttributes &arg)=default
Copy constructor.
size_t GetCacheSize(void) const
Get the cache size
Definition: StandardAttributes.hpp:104
StandardAttributes & operator=(StandardAttributes &&arg)=default
Move assignment operator
~StandardAttributes(void)=default
Destructs this instance and frees all resources.
size_t CountSet() const
Gets the number of set flags
Definition: StandardAttributes.hpp:92
StandardAttribute
Standard attributes to types
Definition: StandardAttribute.hpp:18
@ None
The attribute value is not set.
Root namespace for the PLCnext API