Menge
Modular Pedestrian Simulation Framework for Research and Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AgentPropertyEffect.h
Go to the documentation of this file.
1 /*
2 
3 License
4 
5 Menge
6 Copyright © and trademark ™ 2012-14 University of North Carolina at Chapel Hill.
7 All rights reserved.
8 
9 Permission to use, copy, modify, and distribute this software and its documentation
10 for educational, research, and non-profit purposes, without fee, and without a
11 written agreement is hereby granted, provided that the above copyright notice,
12 this paragraph, and the following four paragraphs appear in all copies.
13 
14 This software program and documentation are copyrighted by the University of North
15 Carolina at Chapel Hill. The software program and documentation are supplied "as is,"
16 without any accompanying services from the University of North Carolina at Chapel
17 Hill or the authors. The University of North Carolina at Chapel Hill and the
18 authors do not warrant that the operation of the program will be uninterrupted
19 or error-free. The end-user understands that the program was developed for research
20 purposes and is advised not to rely exclusively on the program for any reason.
21 
22 IN NO EVENT SHALL THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE AUTHORS
23 BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
24 DAMAGES, INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
25 DOCUMENTATION, EVEN IF THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL OR THE
26 AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS SPECIFICALLY
29 DISCLAIM ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
30 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE AND ANY STATUTORY WARRANTY
31 OF NON-INFRINGEMENT. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND
32 THE UNIVERSITY OF NORTH CAROLINA AT CHAPEL HILL AND THE AUTHORS HAVE NO OBLIGATIONS
33 TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
34 
35 Any questions or comments should be sent to the authors {menge,geom}@cs.unc.edu
36 
37 */
38 
45 #ifndef __AGENT_PROPERT_EFFECT_H__
46 #define __AGENT_PROPERT_EFFECT_H__
47 
48 #include "EventEffectFactory.h"
49 #include "AgentEventEffect.h"
51 
52 namespace Menge {
53 
54  // forward declaration
55  namespace Agents {
56  class BaseAgent;
57  }
58 
66  template <class Manipulator>
67  class MENGE_API AgentPropertyEffect : public AgentEventEffect {
68  public:
73 
77  Manipulator * getManipulator() { return &_manip; }
78 
79  protected:
80 
89  virtual void agentEffect( Agents::BaseAgent * agent ) { _manip.manipulate( agent ); }
90 
94  Manipulator _manip;
95  };
96 
98 
102  template < class Manipulator >
104  public:
109  _propertyID = _attrSet.addStringAttribute( "property", true /*required*/ );
110  _generatorID = _attrSet.addFloatDistAttribute( "", true /*required*/, 0.f, 1.f );
111  }
112 
113  protected:
132  virtual bool setFromXML( EventEffect * effect, TiXmlElement * node, const std::string & behaveFldr ) const {
133  AgentPropertyEffect< Manipulator > * aEffect = dynamic_cast< AgentPropertyEffect< Manipulator > * >( effect );
134  assert( aEffect != 0x0 && "Trying to set agent event effect properties on an incompatible object" );
135 
136  // This parses the target
137  if ( ! EventEffectFactory::setFromXML( aEffect, node, behaveFldr ) ) return false;
138 
139  // Configure manipulator
140  AgentPropertyManipulator * manip = aEffect->getManipulator();
141 
142  BFSM::PropertyOperand prop = parsePropertyName( _attrSet.getString( _propertyID ) );
143  manip->setProperty( prop );
144  if ( prop == BFSM::NO_PROPERTY ) {
145  logger << Logger::ERR_MSG << "The property event effect defined on line " << node->Row() << " specified an invalid value for the \"property\" attribute";
146  return false;
147  }
148  manip->setGenerator( _attrSet.getFloatGenerator( _generatorID ) );
149 
150  return true;
151  }
152 
156  size_t _propertyID;
157 
161  size_t _generatorID;
162  };
163 
165 
169  class MENGE_API SetAgentPropertyEffectFactory : public AgentPropertyEffectFactory< SetPropertyManipulator > {
170  public:
171 
180  virtual const char * name() const { return "set_agent_property"; }
181 
189  virtual const char * description() const {
190  return "Causes the specified property to be *replaced* by the user-defined value";
191  };
192 
193  protected:
205  };
206 
208 
212  class MENGE_API OffsetAgentPropertyEffectFactory : public AgentPropertyEffectFactory< OffsetPropertyManipulator > {
213  public:
214 
223  virtual const char * name() const { return "offset_agent_property"; }
224 
232  virtual const char * description() const {
233  return "Causes the specified property to be offset by the user-defined value";
234  };
235 
236  protected:
248  };
249 
251 
255  class MENGE_API ScaleAgentPropertyEffectFactory : public AgentPropertyEffectFactory< ScalePropertyManipulator > {
256  public:
257 
266  virtual const char * name() const { return "scale_agent_property"; }
267 
275  virtual const char * description() const {
276  return "Causes the specified property to be scaled by the user-defined value";
277  };
278 
279  protected:
291  };
292 
293 } // namespace Menge
294 
295 #endif // __AGENT_PROPERT_EFFECT_H__
AgentPropertyEffect()
Constructor.
Definition: AgentPropertyEffect.h:72
virtual const char * description() const
A description of the effect.
Definition: AgentPropertyEffect.h:232
virtual const char * name() const
The name of the effect.
Definition: AgentPropertyEffect.h:266
EventEffect * instance() const
Create an instance of this class's effect.
Definition: AgentPropertyEffect.h:290
BFSM::PropertyOperand parsePropertyName(const std::string &opName)
Helper function for parsing property actions.
Definition: AgentPropertyManipulator.cpp:59
The core namespace. All elements of Menge are contained in this namespace.
Definition: AgentGenerator.cpp:43
size_t _generatorID
The identifier for the float distribution attribute.
Definition: AgentPropertyEffect.h:161
virtual const char * name() const
The name of the effect.
Definition: AgentPropertyEffect.h:223
void setProperty(BFSM::PropertyOperand prop)
Sets the property operand.
Definition: AgentPropertyManipulator.h:130
virtual const char * description() const
A description of the effect.
Definition: AgentPropertyEffect.h:189
Factory for the SetPropertyEffect.
Definition: AgentPropertyEffect.h:169
virtual const char * name() const
The name of the effect.
Definition: AgentPropertyEffect.h:180
The factory for agent property event effects.
Definition: AgentPropertyEffect.h:103
Manipulator _manip
The manipulator responsible for changing agent properties.
Definition: AgentPropertyEffect.h:94
void setGenerator(FloatGenerator *gen)
Sets the generator for the manipulator.
Definition: AgentPropertyManipulator.cpp:170
virtual bool setFromXML(EventEffect *element, TiXmlElement *node, const std::string &specFldr) const
Given a pointer to an element instance, sets the appropriate fields from the provided XML node...
Definition: ElementFactory.h:176
The definition of a response to an event.
Definition: EventEffect.h:65
Classes for manipulating agent properties in an "undoable" manner (albeit, to a limited degree)...
EventEffect * instance() const
Create an instance of this class's effect.
Definition: AgentPropertyEffect.h:247
Manipulator * getManipulator()
Returns a pointer to the manipulator.
Definition: AgentPropertyEffect.h:77
The base class for generating event effects.
Definition: EventEffectFactory.h:56
The base class event effect changes agent properties.
Definition: AgentPropertyEffect.h:67
Logger logger
Globally available Logger.
Definition: Logger.cpp:49
virtual const char * description() const
A description of the effect.
Definition: AgentPropertyEffect.h:275
Base class for manipulating agent properties in an undoable manner. The undo is limited, it only maintains knowledge of one manipulation. If multiple manipulations are applied, only the last can be undone.
Definition: AgentPropertyManipulator.h:83
AgentPropertyEffectFactory()
Constructor.
Definition: AgentPropertyEffect.h:108
Defines the basic agent properties and functionality that all simulation agents share.
Definition: BaseAgent.h:123
Factory for the OffsetPropertyEffect.
Definition: AgentPropertyEffect.h:212
The namespace that contains the basic simulation mechanisms.
EventEffect * instance() const
Create an instance of this class's effect.
Definition: AgentPropertyEffect.h:204
Factory for the ScalePropertyEffect.
Definition: AgentPropertyEffect.h:255
Error encountered but not handled.
Definition: Logger.h:69
The event effect class that operates on sets of agents.
Definition: AgentEventEffect.h:63
The definition of the agent event effect – defines the agent-base effect.
The definition of the basic event effect factory.
size_t _propertyID
The identifier for the "property" string attribute.
Definition: AgentPropertyEffect.h:156
virtual void agentEffect(Agents::BaseAgent *agent)
The actual work of the effect.
Definition: AgentPropertyEffect.h:89
virtual bool setFromXML(EventEffect *effect, TiXmlElement *node, const std::string &behaveFldr) const
Given a pointer to an AgentPropertyEffect instance, sets the appropriate fields from the provided XML...
Definition: AgentPropertyEffect.h:132