29 #define _unused(x) ((void)(x)) 31 #include "SUAPI-CppWrapper/model/Entity.hpp" 38 #include "SUAPI-CppWrapper/model/AttributeDictionary.hpp" 39 #include "SUAPI-CppWrapper/model/Model.hpp" 40 #include "SUAPI-CppWrapper/model/Entities.hpp" 85 Entity::operator SUEntityRef()
const {
90 Entity::operator SUEntityRef*() {
95 SUEntityRef Entity::ref()
const{
112 throw std::logic_error(
"CW::Entity::attribute_dictionaries(): Entity is null");
114 size_t num_dicts = 0;
115 SUResult res = SUEntityGetNumAttributeDictionaries(
m_entity, &num_dicts);
116 assert(res == SU_ERROR_NONE);
117 if (num_dicts == 0) {
118 return std::vector<AttributeDictionary>{};
120 std::vector<SUAttributeDictionaryRef> dicts_ref(num_dicts, SU_INVALID);
121 res = SUEntityGetAttributeDictionaries(
m_entity, num_dicts, dicts_ref.data(), &num_dicts);
122 assert(res == SU_ERROR_NONE); _unused(res);
123 std::vector<AttributeDictionary> dicts(num_dicts);
124 std::transform(dicts_ref.begin(), dicts_ref.end(), dicts.begin(),
125 [](
const SUAttributeDictionaryRef& value) {
133 throw std::logic_error(
"CW::Entity::attribute_dictionary(): Entity is null");
135 char const *c_name = name.c_str();
136 SUAttributeDictionaryRef dict_ref = SU_INVALID;
137 SUResult res = SUEntityGetAttributeDictionary(
m_entity, &c_name[0], &dict_ref);
138 if (res == SU_ERROR_NONE) {
147 SUResult res = SUEntityAddAttributeDictionary(
m_entity, dict.
ref());
148 if (res == SU_ERROR_NONE) {
157 if (!(*
this) || !entity) {
158 throw std::logic_error(
"CW::Entity::copy_attributes_from(): Entity is null");
161 for (
size_t i=0; i < atts_from.size(); i++) {
162 std::vector<std::string> from_keys = atts_from[i].get_keys();
163 for (
size_t j=0; j < from_keys.size(); j++) {
164 set_attribute(atts_from[i].get_name(), from_keys[j], atts_from[i].get_value(from_keys[j]));
187 throw std::logic_error(
"CW::Entity::entityID(): Entity is null");
189 int32_t entity_id = SU_INVALID;
190 SUEntityGetID(
m_entity, &entity_id);
197 throw std::logic_error(
"CW::Entity::get_attribute(): Entity is null");
206 throw std::logic_error(
"CW::Entity::get_attribute(): Entity is null");
219 throw std::logic_error(
"CW::Entity::set_attribute(): Entity is null");
228 throw std::logic_error(
"CW::Entity::set_attribute(): Entity is null");
236 throw std::logic_error(
"CW::Entity::entity_type(): Entity is null");
243 throw std::logic_error(
"CW::Entity::parent(): Entity is null");
245 SUModelRef
model = SU_INVALID;
246 SUResult res = SUEntityGetModel(
m_entity, &model);
247 assert(res == SU_ERROR_NONE); _unused(res);
248 return Model(model,
false);
253 throw std::logic_error(
"CW::Entity::parent(): Entity is null");
255 SUEntitiesRef entities = SU_INVALID;
256 SUResult res = SUEntityGetParentEntities(
m_entity, &entities);
257 assert(res == SU_ERROR_NONE); _unused(res);
264 SUResult res = SUEntityGetPersistentID(
m_entity, &pid);
265 assert(res == SU_ERROR_NONE); _unused(res);
292 return !(lhs == rhs);
bool m_attached
Indicates whether the Entity has been attached to a model.
SUAttributeDictionaryRef ref() const
TypedValue get_attribute(const std::string &dict_name, const std::string &key, const TypedValue &default_value=TypedValue()) const
Retrieves the value of an attribute in the entity's attribute dictionary.
Entity()
Constructor representing a null objject.
bool attached() const
Returns true if the entity is attached to another object.
friend bool operator==(const Entity &lhs, const Entity &rhs)
Equality operator for two entity objects.
friend bool operator!=(const Entity &lhs, const Entity &rhs)
Non-equality operator for two entity objects.
bool copy_attributes_from(const Entity &entity)
Copies attributes from another Entity object to this one.
std::vector< AttributeDictionary > attribute_dictionaries() const
Returns the AttributeDictionaries collection attached to the entity.
TypedValue get_attribute(const std::string &key, const TypedValue &default_value) const
enum SURefType entity_type() const
Returns the type of the entity. See enum SURefType.
SUEntityRef m_entity
The C SUEntityRef that this class wraps.
int32_t entityID() const
Retrieve a unique ID assigned to an entity.
bool is_valid() const
Checks if the entity is valid.
bool add_dictionary(AttributeDictionary &dict)
Adds the AttributeDictionary to the Entity.
bool operator!() const
Returns true if this entity is not valid. Alias of !is_valid().
int64_t persistent_id() const
bool set_attribute(const std::string &dict_name, const std::string &key, const TypedValue &value)
Sets the value of an attribute in the given AttributeDictionary object.
AttributeDictionary attribute_dictionary(const std::string &name) const
Returns an attribute dictionary object with a given name that is attached to an Entity.
bool set_attribute(const std::string &key, const TypedValue &value)
Entity & operator=(const Entity &other)
Copy assignment operator.