2014-09-13 10:34:30 +02:00
|
|
|
/*
|
|
|
|
|
Copyright (C) 2014 Erik Ogenvik
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#include "DomainProperty.h"
|
2014-09-24 22:00:54 +02:00
|
|
|
#include "PhysicalDomain.h"
|
|
|
|
|
#include "VoidDomain.h"
|
2014-09-13 10:34:30 +02:00
|
|
|
#include "LocatedEntity.h"
|
|
|
|
|
|
2015-04-28 20:56:15 +02:00
|
|
|
PropertyInstanceState<Domain> DomainProperty::sInstanceState;
|
|
|
|
|
|
2014-09-13 10:34:30 +02:00
|
|
|
DomainProperty::DomainProperty()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DomainProperty::DomainProperty(const DomainProperty& rhs)
|
2015-04-28 20:56:15 +02:00
|
|
|
: Property(rhs)
|
2014-09-13 10:34:30 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 20:56:15 +02:00
|
|
|
void DomainProperty::install(LocatedEntity *entity, const std::string &)
|
|
|
|
|
{
|
|
|
|
|
sInstanceState.addState(entity, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-09-13 10:34:30 +02:00
|
|
|
void DomainProperty::remove(LocatedEntity * entity, const std::string &)
|
|
|
|
|
{
|
2015-04-28 20:56:15 +02:00
|
|
|
sInstanceState.removeState(entity);
|
2014-09-13 10:34:30 +02:00
|
|
|
entity->setFlags(~entity_domain);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DomainProperty::apply(LocatedEntity * entity)
|
|
|
|
|
{
|
2014-09-24 22:00:54 +02:00
|
|
|
if (m_data != "") {
|
2015-04-28 20:56:15 +02:00
|
|
|
Domain* domain = sInstanceState.getState(entity);
|
|
|
|
|
if (!domain) {
|
2014-09-24 22:00:54 +02:00
|
|
|
if (m_data == "physical") {
|
2015-04-28 20:56:15 +02:00
|
|
|
domain = new PhysicalDomain(*entity);
|
|
|
|
|
sInstanceState.replaceState(entity, domain);
|
|
|
|
|
entity->setFlags(entity_domain);
|
2014-09-24 22:00:54 +02:00
|
|
|
} else if (m_data == "void") {
|
2015-04-28 20:56:15 +02:00
|
|
|
domain = new VoidDomain(*entity);
|
|
|
|
|
sInstanceState.replaceState(entity, domain);
|
|
|
|
|
entity->setFlags(entity_domain);
|
2014-09-24 22:00:54 +02:00
|
|
|
}
|
2014-09-13 10:34:30 +02:00
|
|
|
}
|
|
|
|
|
} else {
|
2015-04-28 20:56:15 +02:00
|
|
|
sInstanceState.replaceState(entity, nullptr);
|
2014-09-13 10:34:30 +02:00
|
|
|
entity->setFlags(~entity_domain);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DomainProperty * DomainProperty::copy() const
|
|
|
|
|
{
|
|
|
|
|
return new DomainProperty(*this);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-28 20:56:15 +02:00
|
|
|
Domain* DomainProperty::getDomain(const LocatedEntity *entity) const {
|
|
|
|
|
return sInstanceState.getState(entity);
|
2014-09-13 10:34:30 +02:00
|
|
|
}
|
|
|
|
|
|