Hopsan
HopsanEssentials Class Reference

This class gives access to HopsanCore for model and externalLib loading as well as component creation and simulation. More...

Public Member Functions

 HopsanEssentials ()
 HopsanEssentials Constructor.
 
 ~HopsanEssentials ()
 HopsanEssentials Destructor. More...
 
const char * getCoreVersion () const
 Returns the HopsanCore version as a string.
 
const char * getCoreBuildTime () const
 Returns the HopsanCore build date and time.
 
const char * getCoreCompiler () const
 Get compiler info from core.
 
bool isCore64Bit () const
 Check if core is compiled 64-bit. More...
 
bool isCoreDebugCompiled () const
 
ComponentcreateComponent (const HString &rTypeName)
 Creates a component with the specified key-value and returns a pointer to this component. More...
 
ComponentSystemcreateComponentSystem ()
 Creates a ComponentSystem. More...
 
ConditionalComponentSystemcreateConditionalComponentSystem ()
 Creates a ConditionalComponentSystem. More...
 
void removeComponent (Component *pComponent)
 
void removeNode (Node *pNode)
 
bool hasComponent (const HString &rType) const
 Check if a component with given typename exist in the ComponentFactory. More...
 
bool reserveComponentTypeName (const HString &rTypeName)
 Reserves a component TypeName in the component factory map. More...
 
const std::vector< HStringgetRegisteredComponentTypes () const
 Returns a vector containing all registered component types.
 
NodecreateNode (const HString &rNodeType)
 Creates a Node of given node type. More...
 
const std::vector< HStringgetRegisteredNodeTypes () const
 Returns a vector containing all registered node types.
 
bool haveQuantity (const HString &rQuantity) const
 Check if a quantity name is registered. More...
 
HopsanCoreMessageHandlergetCoreMessageHandler ()
 Returns a pointer to the core message handler, do NOT use this function to get messages.
 
void getMessage (HString &rMessage, HString &rType, HString &rTag)
 Get the message waiting on the message queue. More...
 
size_t checkMessage ()
 Check if there are any messages waiting in the queue. More...
 
size_t getNumInfoMessages () const
 Returns the number of waiting info messages on the message queue.
 
size_t getNumWarningMessages () const
 Returns the number of waiting warning messages on the message queue.
 
size_t getNumErrorMessages () const
 Returns the number of waiting error messages on the message queue.
 
size_t getNumFatalMessages () const
 Returns the number of waiting fatal messages on the message queue.
 
size_t getNumDebugMessages () const
 Returns the number of waiting debug messages on the message queue.
 
bool openCoreLogFile (const char *absoluteFilePath)
 Opens the HopsanCore runtime log file, if not already opened. More...
 
bool loadExternalComponentLib (const char *path)
 Loads an external component library. More...
 
bool unLoadExternalComponentLib (const char *path)
 Unloads an external component library. More...
 
void getExternalComponentLibNames (std::vector< HString > &rLibNames)
 Get the libNames of the currently loaded libs (the names compiled into libs) More...
 
void getExternalLibraryContents (const char *libPath, std::vector< HString > &rComponents, std::vector< HString > &rNodes)
 Get the contents (components and nodes) registered by an external library. More...
 
void getLibPathForComponentType (const HString &rTypeName, HString &rLibPath)
 Returns the path to the library file from where specified component is loaded. More...
 
ComponentSystemloadHMFModelFile (const char *filePath, double &rStartTime, double &rStopTime)
 This function is used to load a HMF file. More...
 
ComponentSystemloadHMFModel (const std::vector< unsigned char > xmlVector)
 
ComponentSystemloadHMFModel (const char *xmlString, double &rStartTime, double &rStopTime)
 This function is used to load a HMF model from a string. More...
 
SimulationHandlergetSimulationHandler ()
 

Detailed Description

This class gives access to HopsanCore for model and externalLib loading as well as component creation and simulation.

Constructor & Destructor Documentation

◆ ~HopsanEssentials()

Member Function Documentation

◆ checkMessage()

size_t checkMessage ( )

Check if there are any messages waiting in the queue.

Returns
The number of waiting messages

◆ createComponent()

Component * createComponent ( const HString rTypeName)

Creates a component with the specified key-value and returns a pointer to this component.

Parameters
[in]rTypeNameThe unique type identifier of the component to create

<

◆ createComponentSystem()

ComponentSystem * createComponentSystem ( )

Creates a ComponentSystem.

Returns
A pointer to the ComponentSystem created

◆ createConditionalComponentSystem()

ConditionalComponentSystem * createConditionalComponentSystem ( )

Creates a ConditionalComponentSystem.

Returns
A pointer to the ComponentSystem created

◆ createNode()

Node * createNode ( const HString rNodeType)

Creates a Node of given node type.

Parameters
[in]rNodeTypeThe type of node to create
Returns
A pointer to the created node

◆ getExternalComponentLibNames()

void getExternalComponentLibNames ( std::vector< HString > &  rLibNames)

Get the libNames of the currently loaded libs (the names compiled into libs)

Parameters
[out]rLibNamesA reference to the vector that will contain the lib names

◆ getExternalLibraryContents()

void getExternalLibraryContents ( const char *  libPath,
std::vector< HString > &  rComponents,
std::vector< HString > &  rNodes 
)

Get the contents (components and nodes) registered by an external library.

Parameters
[in]libPathPath to the external library
[out]rComponentsA reference to the vector that will contain the component names
[out]rNodesA reference to the vector that will contain the node names

◆ getLibPathForComponentType()

void getLibPathForComponentType ( const HString rTypeName,
HString rLibPath 
)

Returns the path to the library file from where specified component is loaded.

Parameters
rTypeNameType name of component
rLibPathReference string where path is stored

◆ getMessage()

void getMessage ( HString rMessage,
HString rType,
HString rTag 
)

Get the message waiting on the message queue.

Parameters
[out]rMessageA reference to the message string
[out]rTypeA reference to the message type string
[out]rTagA reference to the message type Tag

◆ hasComponent()

bool hasComponent ( const HString rType) const

Check if a component with given typename exist in the ComponentFactory.

Parameters
[in]rTypeThe typename to check
Returns
True or False depending on if type exist

◆ haveQuantity()

bool haveQuantity ( const HString rQuantity) const

Check if a quantity name is registered.

Parameters
[in]rQuantityThe name of the quantity
Returns
true if the quantity is registered, else false

◆ isCore64Bit()

bool isCore64Bit ( ) const

Check if core is compiled 64-bit.

Returns
Returns true if core is compiled as 64-bit else returns false

◆ loadExternalComponentLib()

bool loadExternalComponentLib ( const char *  path)

Loads an external component library.

Parameters
[in]pathThe path to the library DLL or SO file
Returns
True if loaded successfully, otherwise false

◆ loadHMFModel()

ComponentSystem * loadHMFModel ( const char *  xmlString,
double &  rStartTime,
double &  rStopTime 
)

This function is used to load a HMF model from a string.

Parameters
[in]xmlStringThe model xml string
[out]rStartTimeA reference to the starttime variable
[out]rStopTimeA reference to the stoptime variable
Returns
A pointer to the root system of the loaded model

◆ loadHMFModelFile()

ComponentSystem * loadHMFModelFile ( const char *  filePath,
double &  rStartTime,
double &  rStopTime 
)

This function is used to load a HMF file.

Parameters
[in]filePathThe name (path) of the HMF file
[out]rStartTimeA reference to the starttime variable
[out]rStopTimeA reference to the stoptime variable
Returns
A pointer to the root system of the loaded model

◆ openCoreLogFile()

bool openCoreLogFile ( const char *  absoluteFilePath)

Opens the HopsanCore runtime log file, if not already opened.

Parameters
[in]absoluteFilePathThe file path of the log file
Returns
True if the file could be opened, else false

◆ removeComponent()

void removeComponent ( Component pComponent)

◆ reserveComponentTypeName()

bool reserveComponentTypeName ( const HString rTypeName)

Reserves a component TypeName in the component factory map.

Parameters
[in]rTypeNameThe TypeName to reserve

◆ unLoadExternalComponentLib()

bool unLoadExternalComponentLib ( const char *  path)

Unloads an external component library.

Parameters
[in]pathThe path to the library DLL or SO file to unload
Returns
True if unloaded successfully, otherwise false