Component.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_FRAMEWORK_COMPONENT_H
#define SURGSIM_FRAMEWORK_COMPONENT_H
#include <memory>
#include <string>
#include <boost/uuid/uuid.hpp>
#include "SurgSim/Framework/Accessible.h"
#include "SurgSim/Framework/ObjectFactory.h"
namespace SurgSim
{
namespace Framework
{
// Forward References
class PoseComponent;
class Runtime;
class Scene;
class SceneElement;
class Component :
public Accessible,
public std::enable_shared_from_this<Component>,
public FactoryBase1<Component, std::string>
{
public:
explicit Component(const std::string& name);
virtual ~Component();
std::string getName() const;
std::string getFullName() const;
void setName(const std::string& name);
boost::uuids::uuid getUuid() const;
bool isInitialized() const;
bool initialize(const std::weak_ptr<Runtime>& runtime);
bool isAwake() const;
bool wakeUp();
void retire();
void setScene(std::weak_ptr<Scene> scene);
std::shared_ptr<Scene> getScene();
void setSceneElement(std::weak_ptr<SceneElement> sceneElement);
std::shared_ptr<SceneElement> getSceneElement();
std::shared_ptr<const SceneElement> getSceneElement() const;
std::shared_ptr<Runtime> getRuntime() const;
virtual std::string getClassName() const;
std::shared_ptr<Component> getSharedPtr();
virtual bool doInitialize() = 0;
virtual bool doWakeUp() = 0;
virtual void doRetire();
bool isActive() const;
virtual void setLocalActive(bool val);
bool isLocalActive() const;
protected:
virtual std::shared_ptr<PoseComponent> getPoseComponent();
virtual std::shared_ptr<const PoseComponent> getPoseComponent() const;
private:
std::string m_name;
boost::uuids::uuid m_uuid;
std::weak_ptr<Runtime> m_runtime;
std::weak_ptr<Scene> m_scene;
std::weak_ptr<SceneElement> m_sceneElement;
bool m_didInit;
bool m_didWakeUp;
bool m_isInitialized;
bool m_isAwake;
bool m_isLocalActive;
};
template <class Target, class Source>
std::shared_ptr<Target> checkAndConvert(std::shared_ptr<Source> incoming, const std::string& expectedTypeName);
}; // namespace Framework
}; // namespace SurgSim
#include "SurgSim/Framework/Component-inl.h"
#endif // SURGSIM_FRAMEWORK_COMPONENT_H
SurgSim::Framework::Component::getRuntime
std::shared_ptr< Runtime > getRuntime() const
Get the runtime which contains this component.
Definition: Component.cpp:141
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Framework::Component::m_name
std::string m_name
Name of this component.
Definition: Component.h:165
SurgSim::Framework::checkAndConvert
std::shared_ptr< Target > checkAndConvert(std::shared_ptr< Source > incoming, const std::string &expectedTypeName)
The function tries to convert the Source type to the Target type it will throw if Target is not a sub...
Definition: Component-inl.h:27
SurgSim::Framework::Component::m_didInit
bool m_didInit
Indicates if doInitialize() has been called.
Definition: Component.h:180
SurgSim::Framework::Component::wakeUp
bool wakeUp()
Wakeup this component, this will be called when the component is inserted into the ComponentManager t...
Definition: Component.cpp:93
SurgSim::Framework::Component::doInitialize
virtual bool doInitialize()=0
Interface to be implemented by derived classes.
SurgSim::Framework::FactoryBase1
CRTP Base class to implement Object Factory functionality on a base class, use this rather than writi...
Definition: ObjectFactory.h:140
SurgSim::Framework::Component::setScene
void setScene(std::weak_ptr< Scene > scene)
Sets the scene.
Definition: Component.cpp:116
SurgSim::Framework::Component::Component
Component(const std::string &name)
Constructor.
Definition: Component.cpp:34
Accessible.h
SurgSim::Framework::Component::getSceneElement
std::shared_ptr< SceneElement > getSceneElement()
Gets the scene element.
Definition: Component.cpp:131
SurgSim::Framework::Component::doRetire
virtual void doRetire()
Interface to be implemented by derived classes Has a default implementation, does nothing...
Definition: Component.cpp:111
SurgSim::Framework::Component::m_scene
std::weak_ptr< Scene > m_scene
Scene which contains this component.
Definition: Component.h:174
SurgSim::Framework::Component::doWakeUp
virtual bool doWakeUp()=0
Interface to be implemented by derived classes.
SurgSim::Framework::Component::getSharedPtr
std::shared_ptr< Component > getSharedPtr()
Gets a shared pointer to this component.
Definition: Component.cpp:170
SurgSim::Framework::Component::retire
void retire()
Retire this component, this will be called when the component is removed from the ComponentManager th...
Definition: Component.cpp:105
ObjectFactory.h
SurgSim::Framework::Component::getUuid
boost::uuids::uuid getUuid() const
Gets the id of the component.
Definition: Component.cpp:158
SurgSim::Framework::Component
Component is the main interface class to pass information to the system managers each will decide whe...
Definition: Component.h:42
SurgSim::Framework::Component::getPoseComponent
virtual std::shared_ptr< PoseComponent > getPoseComponent()
Get the PoseComponent for this component.
Definition: Component.cpp:152
SurgSim::Framework::Component::m_sceneElement
std::weak_ptr< SceneElement > m_sceneElement
SceneElement which contains this component.
Definition: Component.h:177
SurgSim::Framework::Component::initialize
bool initialize(const std::weak_ptr< Runtime > &runtime)
Initialize this component, this needs to be called before wakeUp() can be called. ...
Definition: Component.cpp:77
SurgSim::Framework::Component::getName
std::string getName() const
Gets component name.
Definition: Component.cpp:51
SurgSim::Framework::Component::isActive
bool isActive() const
Definition: Component.cpp:184
SurgSim::Framework::Component::m_isInitialized
bool m_isInitialized
Indicates if this component is initialized.
Definition: Component.h:186
SurgSim::Framework::Component::setLocalActive
virtual void setLocalActive(bool val)
Set the component&#39;s active state.
Definition: Component.cpp:196
SurgSim::Framework::Component::m_isLocalActive
bool m_isLocalActive
Indicates if this component is active.
Definition: Component.h:192
SurgSim::Framework::Component::setName
void setName(const std::string &name)
Sets the name of component.
Definition: Component.cpp:67
SurgSim::Framework::Component::m_runtime
std::weak_ptr< Runtime > m_runtime
Runtime which contains this component.
Definition: Component.h:171
SurgSim::Framework::Component::getClassName
virtual std::string getClassName() const
The class name for this class, this being the base class it should return SurgSim::Framework::Compone...
Definition: Component.cpp:163
Component-inl.h
SurgSim::Framework::Component::m_isAwake
bool m_isAwake
Indicates if this component is awake.
Definition: Component.h:189
SurgSim::Framework::Component::isInitialized
bool isInitialized() const
Definition: Component.cpp:72
SurgSim::Framework::Component::m_uuid
boost::uuids::uuid m_uuid
Id of this component.
Definition: Component.h:168
SurgSim::Framework::Accessible
Mixin class for enabling a property system on OSS classes, the instance still needs to initialize pro...
Definition: Accessible.h:37
SurgSim::Framework::Component::isLocalActive
bool isLocalActive() const
Definition: Component.cpp:201
SurgSim::Framework::Component::getFullName
std::string getFullName() const
Gets a string containing the name of the Component and (if it has one) its SceneElement.
Definition: Component.cpp:56
SurgSim::Framework::Component::~Component
virtual ~Component()
Destructor.
Definition: Component.cpp:47
SurgSim::Framework::Component::isAwake
bool isAwake() const
Definition: Component.cpp:88
SurgSim::Framework::Component::m_didWakeUp
bool m_didWakeUp
Indicates if doWakeup() has been called.
Definition: Component.h:183
SurgSim::Framework::Component::getScene
std::shared_ptr< Scene > getScene()
Gets the scene.
Definition: Component.cpp:121
SurgSim::Framework::Component::setSceneElement
void setSceneElement(std::weak_ptr< SceneElement > sceneElement)
Sets the scene element.
Definition: Component.cpp:126