PLCnext API Documentation  22.9.0.33
ArrayDimension.hpp
1 //
3 // Copyright PHOENIX CONTACT Electronics GmbH
4 //
6 #pragma once
7 #include "Arp/System/Core/Arp.h"
8 
9 #include "Arp/System/Rsc/Services/IRscSerializable.hpp"
10 #include "Arp/System/Rsc/Services/RscReader.hpp"
11 #include "Arp/System/Rsc/Services/RscString.hxx"
12 #include "Arp/System/Rsc/Services/RscWriter.hpp"
13 
14 namespace Arp { namespace Plc { namespace Commons { namespace Meta
15 {
16 
17 using namespace Arp::System::Rsc::Services;
18 
21 {
22 public: // typedefs
23 
24 public: // construction/destruction
26  ArrayDimension(void) = default;
28  explicit ArrayDimension(size_t count);
30  ArrayDimension(uint32 count, int32 offset);
32  ArrayDimension(const ArrayDimension& arg) = default;
34  ArrayDimension(ArrayDimension&& arg) = default;
36  ArrayDimension& operator=(const ArrayDimension& arg) = default;
40  ~ArrayDimension(void) override = default;
41 
42 public: // operators
43 
44 public: // setter/getter operations
47  uint32 GetCount(void)const;
48 
51  int32 GetOffset(void)const;
52 
55  static size_t GetCacheSize(void);
56 
57 public: // IRscSerializable operations
58  void Serialize(RscWriter& writer)const override;
59  void Deserialize(RscReader& reader)override;
60  static size_t GetFieldCount(void);
61 
62 private: // static methods
63 
64 private: // methods
65 
66 private: // fields
67  uint32 count = 0;
68  int32 offset = 0;
69 
70 private: // static fields
71 
72 };
73 
75 // inline methods of class ArrayDimension
76 
78 {
79  return this->count;
80 }
81 
83 {
84  return this->offset;
85 }
86 
87 inline size_t ArrayDimension::GetFieldCount(void)
88 {
89  return 2;
90 }
91 
92 inline size_t ArrayDimension::GetCacheSize(void)
93 {
94  size_t cacheSize = 0;
95  cacheSize += sizeof(count);
96  cacheSize += sizeof(offset);
97 
98  return cacheSize;
99 }
100 
101 inline bool operator==(const ArrayDimension& lhs, const ArrayDimension& rhs)
102 {
103  return (lhs.GetCount() == rhs.GetCount()) && (lhs.GetOffset() == rhs.GetOffset());
104 }
105 
106 inline bool operator!= (const ArrayDimension& lhs, const ArrayDimension& rhs)
107 {
108  return !(lhs == rhs);
109 }
110 
111 inline bool operator< (const ArrayDimension& lhs, const ArrayDimension& rhs)
112 {
113  return (lhs.GetCount() < rhs.GetCount()) || ((lhs.GetCount() == rhs.GetCount()) && (lhs.GetOffset() < rhs.GetOffset()));
114 }
115 
116 inline std::ostream& operator<<(std::ostream& os, const ArrayDimension& rhs)
117 {
118  os << "[";
119  if (rhs.GetOffset() != 0)
120  {
121  os << rhs.GetOffset() << "," ;
122  }
123  os << rhs.GetCount() << "]";
124  return os;
125 }
126 
127 }}}} // end of namespace Arp::Plc::Meta
Provide array information.
Definition: ArrayDimension.hpp:21
ArrayDimension(ArrayDimension &&arg)=default
Move constructor.
int32 GetOffset(void) const
Get the index offset of the array for this vector element
Definition: ArrayDimension.hpp:82
uint32 GetCount(void) const
Get the number of array elements for this vector element.
Definition: ArrayDimension.hpp:77
void Deserialize(RscReader &reader) override
Deserializes the datatype. All fields of the datatype have to be deserialized in use of RscReader.
~ArrayDimension(void) override=default
Destructs this instance and frees all resources.
static size_t GetCacheSize(void)
Get the cache size
Definition: ArrayDimension.hpp:92
ArrayDimension(uint32 count, int32 offset)
Constructs an ArrayDimension instance.
ArrayDimension & operator=(ArrayDimension &&arg)=default
Move assignment operator.
void Serialize(RscWriter &writer) const override
Serializes the datatype. All fields of the datatype have to be serialized in use of RscWriter.
ArrayDimension(const ArrayDimension &arg)=default
Copy constructor.
ArrayDimension(void)=default
Constructs an ArrayDimension instance.
ArrayDimension & operator=(const ArrayDimension &arg)=default
Copy assignment operator.
ArrayDimension(size_t count)
Constructs an ArrayDimension instance.
Marshalls structure or class data types. Serialize and Deserialize have to marshal fields in the same...
Definition: IRscSerializable.hpp:19
Reads data from Rsc
Definition: RscReader.hpp:26
Writes data to Rsc.
Definition: RscWriter.hpp:31
std::uint32_t uint32
The Arp unsigned integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:35
std::int32_t int32
The Arp integer type of 4 byte size.
Definition: PrimitiveTypes.hpp:37
Namespace for classes and interfaces for the Remote Service Call implementation
Definition: IRscReadEnumerator.hxx:10
Root namespace for the PLCnext API