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