GDevelop Core
Core library for developing platforms and tools compatible with GDevelop.
EventsBasedObjectVariantsContainer.h
1 /*
2  * GDevelop Core
3  * Copyright 2008-present Florian Rival ([email protected]). All rights
4  * reserved. This project is released under the MIT License.
5  */
6 #pragma once
7 
8 #include <vector>
9 #include "GDCore/Project/EventsBasedObjectVariant.h"
10 #include "GDCore/String.h"
11 #include "GDCore/Tools/SerializableWithNameList.h"
12 
13 namespace gd {
14 class SerializerElement;
15 }
16 
17 namespace gd {
18 
27  : private SerializableWithNameList<gd::EventsBasedObjectVariant> {
28 public:
30 
32  Init(other);
33  }
34 
36  if (this != &other) {
37  Init(other);
38  }
39  return *this;
40  }
41 
45 
48  bool HasVariantNamed(const gd::String& name) const {
49  return Has(name);
50  }
51 
59  return Get(name);
60  }
61 
69  return Get(name);
70  }
71 
79  return Get(index);
80  }
81 
88  const gd::EventsBasedObjectVariant& GetVariant(std::size_t index) const {
89  return Get(index);
90  }
91 
95  std::size_t GetVariantsCount() const { return GetCount(); }
96 
97  gd::EventsBasedObjectVariant& InsertNewVariant(const gd::String& name,
98  std::size_t position) {
99  return InsertNew(name, position);
100  }
101  gd::EventsBasedObjectVariant& InsertVariant(const gd::EventsBasedObjectVariant& object,
102  std::size_t position) {
103  return Insert(object, position);
104  }
105  void RemoveVariant(const gd::String& name) { return Remove(name); }
106  void ClearVariants() { return Clear(); }
107  void MoveVariant(std::size_t oldIndex, std::size_t newIndex) {
108  return Move(oldIndex, newIndex);
109  };
110  std::size_t GetVariantPosition(const gd::EventsBasedObjectVariant& eventsFunction) {
111  return GetPosition(eventsFunction);
112  };
113 
117  const std::vector<std::unique_ptr<gd::EventsBasedObjectVariant>>& GetInternalVector()
118  const {
119  return elements;
120  };
121 
125  std::vector<std::unique_ptr<gd::EventsBasedObjectVariant>>& GetInternalVector() {
126  return elements;
127  };
129 
133 
136  void SerializeVariantsTo(SerializerElement& element) const {
137  return SerializeElementsTo("variant", element);
138  };
139 
144  const SerializerElement& element) {
145  return UnserializeElementsFrom("variant", project, element);
146  };
148  protected:
155  };
156 
157 private:
158 };
159 
160 } // namespace gd
Represents a variation of style of an events-based object.
Definition: EventsBasedObjectVariant.h:25
Used as a base class for classes that will own events-backed variants.
Definition: EventsBasedObjectVariantsContainer.h:27
void Init(const gd::EventsBasedObjectVariantsContainer &other)
Definition: EventsBasedObjectVariantsContainer.h:153
gd::EventsBasedObjectVariant & GetVariant(const gd::String &name)
Get the variant with the specified name.
Definition: EventsBasedObjectVariantsContainer.h:58
void SerializeVariantsTo(SerializerElement &element) const
Serialize events variants.
Definition: EventsBasedObjectVariantsContainer.h:136
const gd::EventsBasedObjectVariant & GetVariant(std::size_t index) const
Get the variant at the specified index in the list.
Definition: EventsBasedObjectVariantsContainer.h:88
bool HasVariantNamed(const gd::String &name) const
Check if the variant with the specified name exists.
Definition: EventsBasedObjectVariantsContainer.h:48
const gd::EventsBasedObjectVariant & GetVariant(const gd::String &name) const
Get the variant with the specified name.
Definition: EventsBasedObjectVariantsContainer.h:68
gd::EventsBasedObjectVariant & GetVariant(std::size_t index)
Get the variant at the specified index in the list.
Definition: EventsBasedObjectVariantsContainer.h:78
void UnserializeVariantsFrom(gd::Project &project, const SerializerElement &element)
Unserialize the events variants.
Definition: EventsBasedObjectVariantsContainer.h:143
std::size_t GetVariantsCount() const
Return the number of variants.
Definition: EventsBasedObjectVariantsContainer.h:95
std::vector< std::unique_ptr< gd::EventsBasedObjectVariant > > & GetInternalVector()
Provide a raw access to the vector containing the variants.
Definition: EventsBasedObjectVariantsContainer.h:125
const std::vector< std::unique_ptr< gd::EventsBasedObjectVariant > > & GetInternalVector() const
Provide a raw access to the vector containing the variants.
Definition: EventsBasedObjectVariantsContainer.h:117
Base class representing a project (game), including all resources, scenes, objects,...
Definition: Project.h:50
A class template that store a list of elements that can be accessed by their names and serialized.
Definition: SerializableWithNameList.h:33
void Init(const SerializableWithNameList< T > &other)
Definition: SerializableWithNameList.inl:190
A generic container that can represent a value ( containing a string, double, bool or int),...
Definition: SerializerElement.h:37
String represents an UTF8 encoded string.
Definition: String.h:33
Definition: CommonTools.h:24