OpenWalnut  1.5.0dev
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
WModuleMetaInformation Class Reference

A class abstracting module meta information. More...

#include <WModuleMetaInformation.h>

+ Collaboration diagram for WModuleMetaInformation:

Classes

struct  Author
 Structure to contain all supported author information. More...
 
struct  Online
 Structure to encapsulate the META info online resources. More...
 
struct  Screenshot
 Structure to encapsulate a screenshot info. More...
 

Public Types

typedef std::shared_ptr< WModuleMetaInformationSPtr
 Convenience typedef for a std::shared_ptr< WModuleMetaInformation >. More...
 
typedef std::shared_ptr< const WModuleMetaInformationConstSPtr
 Convenience typedef for a std::shared_ptr< const WModuleMetaInformation >. More...
 

Public Member Functions

 WModuleMetaInformation (std::string name)
 Constructor. More...
 
 WModuleMetaInformation (std::shared_ptr< WModule > module)
 Construct a meta info object that loads all information from the specified file. More...
 
virtual ~WModuleMetaInformation ()
 Destructor. More...
 
std::string getName () const
 The name of the module. More...
 
boost::filesystem::path getIcon () const
 Get the icon path. More...
 
bool isIconAvailable () const
 Check whether the meta info contained an icon. More...
 
std::string getWebsite () const
 The URL to a module website. More...
 
std::string getDescription () const
 A module description. More...
 
boost::filesystem::path getHelp () const
 Path to a text or HTML file containing some module help. More...
 
std::vector< AuthorgetAuthors () const
 A list of authors. More...
 
std::vector< OnlinegetOnlineResources () const
 A list of online resources. More...
 
std::vector< std::string > getTags () const
 A list of tags provided for the module. More...
 
std::vector< ScreenshotgetScreenshots () const
 Returns the list of screenshots. More...
 
template<typename ResultType >
ResultType query (std::string path, ResultType defaultValue=ResultType()) const
 Query a value from the META file. More...
 
template<typename ResultType >
std::vector< ResultType > query (std::string path, const std::vector< ResultType > &defaultValues) const
 Query multiple values from the META file. More...
 
bool valueExists (std::string path) const
 Check whether the value specified by "path" exists. More...
 

Private Attributes

std::string m_name
 The name of the module providing this meta information. More...
 
std::string m_description
 The default description if none was specified in the META file. More...
 
WStructuredTextParser::StructuredValueTree m_metaData
 The tree representing the data. More...
 
bool m_loaded
 If true, m_metaData should be queried in all getters. More...
 
boost::filesystem::path m_localPath
 The module local path. More...
 

Detailed Description

A class abstracting module meta information.

It encapsulates module name, description, icon, author lists, help resources, online resources and much more. It is guaranteed to, at least, provide a module name. Everything else is optional. It also encapsulates the WStructuredTextParser class for loading the data.

Definition at line 43 of file WModuleMetaInformation.h.

Member Typedef Documentation

◆ ConstSPtr

Convenience typedef for a std::shared_ptr< const WModuleMetaInformation >.

Definition at line 54 of file WModuleMetaInformation.h.

◆ SPtr

Convenience typedef for a std::shared_ptr< WModuleMetaInformation >.

Definition at line 49 of file WModuleMetaInformation.h.

Constructor & Destructor Documentation

◆ WModuleMetaInformation() [1/2]

WModuleMetaInformation::WModuleMetaInformation ( std::string  name)
explicit

Constructor.

The help object will be empty, meaning there is no further meta info available. The name is the only required value. Of course, this is of limited use in most cases.

Parameters
namethe name of the module

Definition at line 36 of file WModuleMetaInformation.cpp.

◆ WModuleMetaInformation() [2/2]

WModuleMetaInformation::WModuleMetaInformation ( std::shared_ptr< WModule module)
explicit

Construct a meta info object that loads all information from the specified file.

If the file exist and could not be parsed, only an error log is printed. No exception is thrown.

Parameters
moduleThe module to load the meta file for.

Definition at line 43 of file WModuleMetaInformation.cpp.

References wlog::error(), m_loaded, m_metaData, m_name, and WException::what().

+ Here is the call graph for this function:

◆ ~WModuleMetaInformation()

WModuleMetaInformation::~WModuleMetaInformation ( )
virtual

Destructor.

Cleans internal list.

Definition at line 74 of file WModuleMetaInformation.cpp.

Member Function Documentation

◆ getAuthors()

std::vector< WModuleMetaInformation::Author > WModuleMetaInformation::getAuthors ( ) const

A list of authors.

If the META file did not contain any author information, this returns the OpenWalnut Team as author.

Returns
Author list.

Definition at line 144 of file WModuleMetaInformation.cpp.

References m_loaded, m_metaData, and m_name.

◆ getDescription()

std::string WModuleMetaInformation::getDescription ( ) const

A module description.

Can be empty but is initialized with the description of the module given on construction.

Returns
the description.

Definition at line 120 of file WModuleMetaInformation.cpp.

References m_description, m_loaded, m_metaData, and m_name.

◆ getHelp()

boost::filesystem::path WModuleMetaInformation::getHelp ( ) const

Path to a text or HTML file containing some module help.

Can be invalid. Check for existence before opening.

Returns
the path to help

Definition at line 132 of file WModuleMetaInformation.cpp.

References m_loaded, m_localPath, m_metaData, and m_name.

◆ getIcon()

boost::filesystem::path WModuleMetaInformation::getIcon ( ) const

Get the icon path.

Can be invalid. Check for existence before opening.

Returns
the path to the icon file

Definition at line 84 of file WModuleMetaInformation.cpp.

References m_loaded, m_localPath, m_metaData, and m_name.

◆ getName()

std::string WModuleMetaInformation::getName ( ) const

The name of the module.

Will always return the name of the module given on construction.

Returns
the name

Definition at line 79 of file WModuleMetaInformation.cpp.

References m_name.

◆ getOnlineResources()

std::vector< WModuleMetaInformation::Online > WModuleMetaInformation::getOnlineResources ( ) const

A list of online resources.

Can be empty.

Returns
list of online material

Definition at line 181 of file WModuleMetaInformation.cpp.

References WModuleMetaInformation::Online::m_description, m_loaded, m_metaData, WModuleMetaInformation::Online::m_name, m_name, and WModuleMetaInformation::Online::m_url.

◆ getScreenshots()

std::vector< WModuleMetaInformation::Screenshot > WModuleMetaInformation::getScreenshots ( ) const

Returns the list of screenshots.

Returns
the screenshot list.

Definition at line 229 of file WModuleMetaInformation.cpp.

References WModuleMetaInformation::Screenshot::m_description, WModuleMetaInformation::Screenshot::m_filename, m_loaded, m_metaData, and m_name.

◆ getTags()

std::vector< std::string > WModuleMetaInformation::getTags ( ) const

A list of tags provided for the module.

Returns
the tag list.

Definition at line 217 of file WModuleMetaInformation.cpp.

References m_loaded, m_metaData, and m_name.

◆ getWebsite()

std::string WModuleMetaInformation::getWebsite ( ) const

The URL to a module website.

Can be empty.

Returns
URL to website

Definition at line 108 of file WModuleMetaInformation.cpp.

References m_loaded, m_metaData, and m_name.

◆ isIconAvailable()

bool WModuleMetaInformation::isIconAvailable ( ) const

Check whether the meta info contained an icon.

Returns
true if icon is available. Does not check existence or validity of image file.

Definition at line 96 of file WModuleMetaInformation.cpp.

References m_loaded, m_metaData, and m_name.

◆ query() [1/2]

template<typename ResultType >
std::vector< ResultType > WModuleMetaInformation::query ( std::string  path,
const std::vector< ResultType > &  defaultValues 
) const
inline

Query multiple values from the META file.

Template Parameters
ResultTypethe type of the result of the query. The function tries to cast the found value to this type. If this is not possible, the default value will be returned.
Parameters
paththe absolute path in the META file. Please be aware that, if you specify a value inside your modules meta block, you need to add the module name too. The path is absolute!
defaultValuesthe default value to return in case of an non-existing element or cast problems.
Exceptions
WTypeMismatchif the value cannot be cast to the specified target type
Returns
the value vector, or defaultType.

Definition at line 247 of file WModuleMetaInformation.h.

References m_metaData.

◆ query() [2/2]

template<typename ResultType >
ResultType WModuleMetaInformation::query ( std::string  path,
ResultType  defaultValue = ResultType() 
) const
inline

Query a value from the META file.

Template Parameters
ResultTypethe type of the result of the query. The function tries to cast the found value to this type. If this is not possible, the default value will be returned.
Parameters
paththe absolute path in the META file. Please be aware that, if you specify a value inside your modules meta block, you need to add the module name too. The path is absolute!
defaultValuethe default value to return in case of an non-existing element or cast problems.
Exceptions
WTypeMismatchif the value cannot be cast to the specified target type
Returns
the value, or defaultType.

Definition at line 227 of file WModuleMetaInformation.h.

References m_metaData.

◆ valueExists()

bool WModuleMetaInformation::valueExists ( std::string  path) const

Check whether the value specified by "path" exists.

Parameters
paththe absolute path in the META file. Please be aware that, if you specify a value inside your modules meta block, you need to add the module name too. The path is absolute!
Returns
true if it exists.

Definition at line 264 of file WModuleMetaInformation.cpp.

References m_loaded, and m_metaData.

Member Data Documentation

◆ m_description

std::string WModuleMetaInformation::m_description
private

The default description if none was specified in the META file.

Initialized with the description of the module specified during construction.

Definition at line 274 of file WModuleMetaInformation.h.

Referenced by getDescription().

◆ m_loaded

bool WModuleMetaInformation::m_loaded
private

If true, m_metaData should be queried in all getters.

If false, you can query m_meta but it will only tell you that the desired value could not be found.

Definition at line 285 of file WModuleMetaInformation.h.

Referenced by getAuthors(), getDescription(), getHelp(), getIcon(), getOnlineResources(), getScreenshots(), getTags(), getWebsite(), isIconAvailable(), valueExists(), and WModuleMetaInformation().

◆ m_localPath

boost::filesystem::path WModuleMetaInformation::m_localPath
private

The module local path.

Used for several meta infos returning a path.

Definition at line 290 of file WModuleMetaInformation.h.

Referenced by getHelp(), and getIcon().

◆ m_metaData

WStructuredTextParser::StructuredValueTree WModuleMetaInformation::m_metaData
private

◆ m_name

std::string WModuleMetaInformation::m_name
private

The name of the module providing this meta information.

Definition at line 268 of file WModuleMetaInformation.h.

Referenced by getAuthors(), getDescription(), getHelp(), getIcon(), getName(), getOnlineResources(), getScreenshots(), getTags(), getWebsite(), isIconAvailable(), and WModuleMetaInformation().


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