Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
SurgSim::Framework::Asset Class Referenceabstract

This class is used to facilitate file loading. More...

#include <SurgSim/Framework/Asset.h>

Inheritance diagram for SurgSim::Framework::Asset:
SurgSim::Framework::Accessible SurgSim::Framework::FactoryBase< Asset > SurgSim::Physics::Fem< FemElementStructs::RotationVectorData, FemElementStructs::FemElement1DParameter > SurgSim::Physics::Fem< FemElementStructs::RotationVectorData, FemElementStructs::FemElement2DParameter > SurgSim::Physics::Fem< SurgSim::DataStructures::EmptyData, FemElementStructs::FemElement3DParameter > SurgSim::DataStructures::OctreeNode< Data > SurgSim::DataStructures::TriangleMesh< VertexData, EdgeData, TriangleData > SurgSim::Graphics::Font SurgSim::Graphics::Model SurgSim::Physics::Fem< VertexData, Element > SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > SurgSim::DataStructures::TriangleMesh< VertexData, EdgeData, SegmentEmptyData > SurgSim::DataStructures::TriangleMesh< VertexData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData >

Public Member Functions

 Asset ()
 Constructor. More...
 
 Asset (const Asset &rhs)
 Copy Constructor. More...
 
virtual ~Asset ()
 Destructor. More...
 
void load (const std::string &fileName, const SurgSim::Framework::ApplicationData &data)
 Load a file with given name using 'data' as look up path(s). More...
 
void load (const std::string &fileName)
 Overloaded function using SurgSim::Framework::Runtime::getApplicationData() as look up path(s). More...
 
std::string getFileName () const
 Return the name of file loaded by this class. More...
 
virtual std::string getClassName () const =0
 Support serialization with a classname. More...
 
- Public Member Functions inherited from SurgSim::Framework::Accessible
 Accessible ()
 Default Constructor. More...
 
 ~Accessible ()
 Destructor. More...
 
template<class T >
getValue (const std::string &name) const
 Retrieves the value with the name by executing the getter if it is found and tries to convert it to the given type. More...
 
boost::any getValue (const std::string &name) const
 Retrieves the value with the name by executing the getter if it is found. More...
 
template<class T >
bool getValue (const std::string &name, T *value) const
 Retrieves the value with the name by executing the getter if it is found, and converts it to the type of the output parameter. More...
 
void setValue (const std::string &name, const boost::any &value)
 Sets a value of a property that has setter. More...
 
bool isReadable (const std::string &name) const
 Check whether a property is readable. More...
 
bool isWriteable (const std::string &name) const
 Check whether a property is writable. More...
 
void setGetter (const std::string &name, GetterType func)
 Sets a getter for a given property. More...
 
void setSetter (const std::string &name, SetterType func)
 Sets a setter for a given property. More...
 
void setAccessors (const std::string &name, GetterType getter, SetterType setter)
 Sets the accessors getter and setter in one function. More...
 
void removeAccessors (const std::string &name)
 Removes all the accessors (getter and setter) for a given property. More...
 
void forwardProperty (const std::string &name, const Accessible &target, const std::string &targetProperty)
 Adds a property with the given name that uses the targets accessors, in effect forwarding the value to the target. More...
 
void setSerializable (const std::string &name, EncoderType encoder, DecoderType decoder)
 Sets the functions used to convert data from and to a YAML::Node. More...
 
void setDecoder (const std::string &name, DecoderType decoder)
 Sets the functions used to convert data from a YAML::Node. More...
 
YAML::Node encode () const
 Encode this Accessible to a YAML::Node. More...
 
void decode (const YAML::Node &node, const std::vector< std::string > &ignoredProperties=std::vector< std::string >())
 Decode this Accessible from a YAML::Node, will throw an exception if the data type cannot be converted. More...
 
template<>
boost::any getValue (const std::string &name) const
 

Protected Member Functions

virtual bool doLoad (const std::string &filePath)=0
 Derived classes will overwrite this method to do actual loading. More...
 

Private Member Functions

void serializeFileName (SurgSim::Framework::Accessible *accessible)
 Wrap the registration calls for the filename property, which is more complicated due to the overloaded function call load() More...
 

Private Attributes

friend AssetTest
 
std::string m_fileName
 Name of the file to be loaded. More...
 

Additional Inherited Members

- Public Types inherited from SurgSim::Framework::Accessible
typedef std::function< boost::any(void)> GetterType
 
typedef std::function< void(boost::any)> SetterType
 
typedef std::function< YAML::Node(void)> EncoderType
 
typedef std::function< void(const YAML::Node *)> DecoderType
 
- Public Types inherited from SurgSim::Framework::FactoryBase< Asset >
typedef ObjectFactory< AssetFactoryType
 
- Static Public Member Functions inherited from SurgSim::Framework::FactoryBase< Asset >
static FactoryTypegetFactory ()
 

Detailed Description

This class is used to facilitate file loading.

It uses the static ApplicationData in SurgSim::Framework::Runtime to load file. Classes not in SurgSim::Framework::Component hierarchy should inherit this class in order to load a file. Components that take assets as parameters should, in addition to their general set<Asset>() and get<Asset>() functions, implement a helper function load<Asset>(), that creates and loads the specified asset. Additionally, a special YAML parameter (<Asset>FileName) should be implemented, that can be used to specify the asset, without having to specify the whole asset in serialized form.

Constructor & Destructor Documentation

◆ Asset() [1/2]

SurgSim::Framework::Asset::Asset ( )

Constructor.

◆ Asset() [2/2]

SurgSim::Framework::Asset::Asset ( const Asset rhs)

Copy Constructor.

◆ ~Asset()

SurgSim::Framework::Asset::~Asset ( )
virtual

Destructor.

Member Function Documentation

◆ doLoad()

virtual bool SurgSim::Framework::Asset::doLoad ( const std::string filePath)
protectedpure virtual

◆ getClassName()

virtual std::string SurgSim::Framework::Asset::getClassName ( ) const
pure virtual

Support serialization with a classname.

Returns
the name of this class

Implemented in SurgSim::DataStructures::TriangleMesh< VertexData, EdgeData, TriangleData >, and SurgSim::DataStructures::OctreeNode< Data >.

◆ getFileName()

std::string SurgSim::Framework::Asset::getFileName ( ) const

Return the name of file loaded by this class.

Returns
Name of the file loaded by this class.

◆ load() [1/2]

void SurgSim::Framework::Asset::load ( const std::string fileName)

Overloaded function using SurgSim::Framework::Runtime::getApplicationData() as look up path(s).

Parameters
fileNameName of the file to be loaded.

◆ load() [2/2]

void SurgSim::Framework::Asset::load ( const std::string fileName,
const SurgSim::Framework::ApplicationData data 
)

Load a file with given name using 'data' as look up path(s).

If 'fileName' is not empty and the file is found, this method calls 'doLoad()' to load the file. Assertions will fail if 'fileName' is empty or file is not found or file loading is unsuccessful.

Note
As a side effect, the name of the file will be recorded in
Asset::m_fileName and can be retrieved by Asset::getFileName().
Parameters
fileNameName of the file to be loaded.
dataApplicationData which provides the runtime look up path(s).

◆ serializeFileName()

void SurgSim::Framework::Asset::serializeFileName ( SurgSim::Framework::Accessible accessible)
private

Wrap the registration calls for the filename property, which is more complicated due to the overloaded function call load()

Parameters
accessible'this' pointer of derived class.

Member Data Documentation

◆ AssetTest

friend SurgSim::Framework::Asset::AssetTest
private

◆ m_fileName

std::string SurgSim::Framework::Asset::m_fileName
private

Name of the file to be loaded.


The documentation for this class was generated from the following files: