Aspose.Tasks for C++
PropertyContainer.h
1 #pragma once
2 //-----------------------------------------------------------------------
3 // <copyright file="PropertyContainer.cs" company="Aspose Pty Ltd">
4 // Copyright (c) 2002-2025 Aspose Pty Ltd. All Rights Reserved.
5 // </copyright>
6 //-----------------------------------------------------------------------
7 
8 #include <system/make_const_ref.h>
9 #include <system/exceptions.h>
10 #include <system/constraints.h>
11 #include <system/array.h>
12 #include <cstdint>
13 
14 #include "aspose.tasks.cpp/Item.h"
15 #include "aspose.tasks.cpp/IContainer.h"
16 #include "EntityPropertyItem.h"
17 #include "aspose.tasks.cpp/Key.h"
18 #include "aspose.tasks.cpp/aspose_tasks_api_defs.h"
19 
20 namespace Aspose {
21 
22 namespace Tasks {
23 
24 /// <summary>
25 /// Represents property container.
26 /// </summary>
27 template<typename T>
28 class ASPOSE_TASKS_SHARED_CLASS PropertyContainer : public Aspose::Tasks::IContainer<T>
29 {
30  assert_is_cs_struct(T);
31 
32  typedef PropertyContainer<T> ThisType;
33  typedef Aspose::Tasks::IContainer<T> BaseType;
34 
35  typedef ::System::BaseTypesInfo<BaseType> ThisTypeBaseTypesInfo;
36  RTTI_INFO_TEMPLATE_CLASS(ThisType, ThisTypeBaseTypesInfo);
37 
38  template<typename FT0> friend class Aspose::Tasks::PropertyContainer;
39 
40 public:
41 
42  PropertyContainer()
43  {
44  this->map = System::MakeArray<System::SharedPtr<Aspose::Tasks::Item>>(ItemsCount());
45 
46  }
47 
48  PropertyContainer(const System::SharedPtr<PropertyContainer<T>>& propertyContainer)
49  {
50  this->map = System::MakeArray<System::SharedPtr<Aspose::Tasks::Item>>(ItemsCount());
51 
52  if (propertyContainer == nullptr)
53  {
54  throw System::ArgumentNullException(u"propertyContainer");
55  }
56 
57  if (propertyContainer->map->get_Length() != ItemsCount())
58  {
59  throw System::InvalidOperationException(u"Enum size");
60  }
61 
62  this->map = System::MakeArray<System::SharedPtr<Aspose::Tasks::Item>>(propertyContainer->map->get_Length());
63 
64  for (int32_t i = 0; i < this->map->get_Length(); i++)
65  {
66  auto containerMap = propertyContainer->map[i];
67  if (containerMap != nullptr)
68  {
69  this->map[i] = containerMap->Clone();
70  }
71  }
72  }
73 
74  template <typename TValue>
75  void Set(const Key<TValue, T>& key, const TValue& val)
76  {
77  this->template CheckPropAndSet<TValue>(key, val);
78  }
79 
80  /// <summary>
81  /// Maps the specified property to the specified value in this container.
82  /// If this container doesn't contain record ProjectItem it will be added.
83  /// </summary>
84  /// <param name="key">the specified property.</param>
85  /// <param name="val">the value.</param>
86  template <typename TValue>
87  void CheckPropAndSet(const Key<TValue, T>& key, const TValue& val)
88  {
89  auto& item = this->map->data_ptr()[key.get_KeyTypeIndex()];
90  if (!item)
91  {
92  item = System::MakeObject<EntityProperty<TValue>>(val);
93  }
94  else
95  {
96  static_cast<EntityProperty<TValue>*>(item.get())->UpdateValue(val);
97  }
98 
99  }
100  template <typename TValue>
101  System::MakeConstRef_t<TValue> Get(const Key<TValue, T>& key)
102  {
103  return this->template CheckPropAndGet<TValue>(key);
104  }
105 
106  /// <summary>
107  /// Returns the value to which the property is mapped in this container.
108  /// If this container doesn't contain record ProjectItem it will be added with default value and default value will be returned.
109  /// </summary>
110  /// <param name="key">the specified property.</param>
111  /// <returns>the value to which the property is mapped in this container or default value for property.</returns>
112  template <typename TValue>
113  System::MakeConstRef_t<TValue> CheckPropAndGet(const Key<TValue, T>& key)
114  {
115  auto& item = this->map->data_ptr()[key.get_KeyTypeIndex()];
116  if (!item)
117  {
118  item = System::MakeObject<EntityProperty<TValue>>();
119  }
120  return static_cast<EntityProperty<TValue>*>(item.get())->get_Val();
121 
122  }
123  template <typename TValue>
124  void Add(const Key<TValue, T>& key, const System::SharedPtr<Item>& val)
125  {
126  this->map[key.get_KeyTypeIndex()] = val;
127  }
128 
129  void SetTemplateWeakPtr(uint32_t argument) override
130  {
131  switch (argument)
132  {
133  case 0:
134  break;
135 
136  }
137  }
138 
139 protected:
140 
141  #ifdef ASPOSE_GET_SHARED_MEMBERS
142  void GetSharedMembers(System::Object::shared_members_type& result) const override
143  {
144  System::Object::GetSharedMembers(result);
145 
146  result.Add("Aspose::Tasks::PropertyContainer::map", this->map);
147  }
148  #endif
149 
150 
151 
152 private:
153 
154  static int32_t& ItemsCount()
155  {
156  static int32_t value = System::Enum<T>::GetValues()->get_Length();
157  return value;
158  }
159 
160  System::ArrayPtr<System::SharedPtr<Item>> map;
161 
162 };
163 
164 } // namespace Tasks
165 } // namespace Aspose
166 
167 
Represents an entity item (property of container class).
Definition: EntityPropertyItem.h:24
Definition: Asn.h:12
Represents a property key of a class of the specified type. An instance of this class is used when ge...
Definition: Asn.h:19
System::MakeConstRef_t< TValue > CheckPropAndGet(const Key< TValue, T > &key)
Returns the value to which the property is mapped in this container. If this container doesn't contai...
Definition: PropertyContainer.h:113
void CheckPropAndSet(const Key< TValue, T > &key, const TValue &val)
Maps the specified property to the specified value in this container. If this container doesn't conta...
Definition: PropertyContainer.h:87
Represents property container.
Definition: Key.h:57