![]() |
![]() |
![]() |
cpg-network Reference Manual | ![]() |
---|---|---|---|---|
Top | Description | Object Hierarchy | Properties | Signals |
#include <cpg-network/cpg-network.h> #define CPG_NETWORK_LOAD_ERROR enum CpgNetworkLoadError; CpgNetworkClass; CpgNetwork; CpgNetwork * cpg_network_new_from_file (const gchar *filename, GError **error); CpgNetwork * cpg_network_new_from_xml (const gchar *xml, GError **error); CpgNetwork * cpg_network_new (void); void cpg_network_set_integrator (CpgNetwork *network, CpgIntegrator *integrator); CpgIntegrator * cpg_network_get_integrator (CpgNetwork *network); gchar * cpg_network_write_to_xml (CpgNetwork *network); void cpg_network_write_to_file (CpgNetwork *network, const gchar *filename); void cpg_network_merge (CpgNetwork *network, CpgNetwork *other); void cpg_network_merge_from_file (CpgNetwork *network, const gchar *filename, GError **error); void cpg_network_merge_from_xml (CpgNetwork *network, const gchar *xml, GError **error); void cpg_network_set_global_constant (CpgNetwork *network, const gchar *name, gdouble constant); CpgObject * cpg_network_get_globals (CpgNetwork *network); void cpg_network_clear (CpgNetwork *network); CpgObject * cpg_network_get_object (CpgNetwork *network, const gchar *id); void cpg_network_add_object (CpgNetwork *network, CpgObject *object); void cpg_network_remove_object (CpgNetwork *network, CpgObject *object); gboolean cpg_network_compile (CpgNetwork *network, CpgCompileError *error); gboolean cpg_network_get_compiled (CpgNetwork *network); void cpg_network_taint (CpgNetwork *network); GSList * cpg_network_get_states (CpgNetwork *network); GSList * cpg_network_get_links (CpgNetwork *network); void cpg_network_run (CpgNetwork *network, gdouble from, gdouble timestep, gdouble to); void cpg_network_step (CpgNetwork *network, gdouble timestep); void cpg_network_reset (CpgNetwork *network); GSList * cpg_network_get_templates (CpgNetwork *network); void cpg_network_add_template (CpgNetwork *network, const gchar *name, CpgObject *object); CpgObject * cpg_network_get_template (CpgNetwork *network, const gchar *name); void cpg_network_remove_template (CpgNetwork *network, const gchar *name); CpgObject * cpg_network_add_from_template (CpgNetwork *network, const gchar *name); CpgObject * cpg_network_add_link_from_template (CpgNetwork *network, const gchar *name, CpgObject *from, CpgObject *to); void cpg_network_add_function (CpgNetwork *network, CpgFunction *function); void cpg_network_remove_function (CpgNetwork *network, CpgFunction *function); GSList * cpg_network_get_functions (CpgNetwork *network); CpgFunction * cpg_network_get_function (CpgNetwork *network, gchar const *name); GSList * cpg_network_get_integration_state (CpgNetwork *network);
"compiled" gboolean : Read / Write / Construct "integrator" CpgIntegrator* : Read / Write
The cpg network is the main component of the cpg-network library. The network consists of CpgState, CpgRelay and CpgLink objects which combined make up the network.
The easiest way of using the library is to write the network using the XML representation (see xml-specification). You then create the network from file using cpg_network_new_from_file. To simulate the network, use cpg_network_run or for running single steps cpg_network_step.
For more information, see Using the network.
typedef enum { CPG_NETWORK_LOAD_ERROR_XML, CPG_NETWORK_LOAD_ERROR_PROPERTY, CPG_NETWORK_LOAD_ERROR_OBJECT, CPG_NETWORK_LOAD_ERROR_LINK, CPG_NETWORK_LOAD_ERROR_FUNCTION } CpgNetworkLoadError;
typedef struct { void (*reset) (CpgNetwork *network); void (*compile_error) (CpgNetwork *network, CpgCompileError *error); } CpgNetworkClass;
CpgNetwork * cpg_network_new_from_file (const gchar *filename, GError **error);
Create a new CPG network by reading the network definition from file
|
the filename of the file containing the network definition |
|
error return value |
Returns : |
the newly created CPG network or NULL if there was an
error reading the file
|
CpgNetwork * cpg_network_new_from_xml (const gchar *xml, GError **error);
Create a new CPG network from the network xml definition
|
xml definition of the network |
|
error return value |
Returns : |
the newly created CPG network or NULL if there was an
error reading the file
|
CpgNetwork * cpg_network_new (void);
Create a new empty CPG network
Returns : |
the newly created CPG network |
void cpg_network_set_integrator (CpgNetwork *network, CpgIntegrator *integrator);
Set the integrator used to integrate the network.
|
A CpgNetwork |
|
A CpgIntegrator |
CpgIntegrator * cpg_network_get_integrator (CpgNetwork *network);
Get the integrator currently associated with the network.
|
A CpgNetwork |
Returns : |
A CpgIntegrator |
gchar * cpg_network_write_to_xml (CpgNetwork *network);
Get xml representation of the network
|
a CpgNetwork |
Returns : |
a string containing the xml representation of the network |
void cpg_network_write_to_file (CpgNetwork *network, const gchar *filename);
Write the xml representation of the network to file
|
a CpgNetwork |
|
a filename |
void cpg_network_merge (CpgNetwork *network, CpgNetwork *other);
Merges all the globals, templates and objects from other
into network
.
|
a CpgNetwork |
|
a CpgNetwork to merge |
void cpg_network_merge_from_file (CpgNetwork *network, const gchar *filename, GError **error);
Merges the network defined in the file filename
into network
. This is
similar to creating a network from a file and merging it with network
.
|
a CpgNetwork |
|
network filename |
|
error return value |
void cpg_network_merge_from_xml (CpgNetwork *network, const gchar *xml, GError **error);
Merges the network defined in xml
into network
. This is
similar to creating a network from xml and merging it with network
.
|
a CpgNetwork |
|
a xml string describing the network |
|
error return value |
void cpg_network_set_global_constant (CpgNetwork *network, const gchar *name, gdouble constant);
Sets a constant in the network. Globals can be used to set global settings for the whole network (e.g. oscillator frequency)
|
a CpgNetwork |
|
the constant name |
|
the constant value |
CpgObject * cpg_network_get_globals (CpgNetwork *network);
Get the CpgObject containing all the global globals
|
a CpgNetwork |
Returns : |
the CpgObject containing the global globals |
void cpg_network_clear (CpgNetwork *network);
Clears the network (removes all objects).
|
a CpgNetwork |
CpgObject * cpg_network_get_object (CpgNetwork *network, const gchar *id);
Find object id
in network
|
a CpgNetwork |
|
the object id |
Returns : |
a CpgObject or NULL if there is no object with id id
|
void cpg_network_add_object (CpgNetwork *network, CpgObject *object);
Adds a new object to the network (either CpgLink or CpgState). Make sure to recompile the network after the object is added.
|
a CpgNetwork |
|
the CpgObject to add |
void cpg_network_remove_object (CpgNetwork *network, CpgObject *object);
Removes object
from the network
|
a CpgNetwork |
|
the CpgObject to remove |
gboolean cpg_network_compile (CpgNetwork *network, CpgCompileError *error);
Recompile all expressions for all states and links. You should do this after you've added new objects to the network. If a simulation is ran while the network is in an uncompiled state, it will be compiled first.
If an error occurs while compiling, this function returns FALSE
and sets
error
accordingly.
|
a CpgNetwork |
|
return location for compiler error |
Returns : |
TRUE if compilation was successful, FALSE otherwise
|
gboolean cpg_network_get_compiled (CpgNetwork *network);
Get whether the network is currently compiled.
|
A CpgNetwork |
Returns : |
TRUE if the network is compiled, FALSE otherwise
|
void cpg_network_taint (CpgNetwork *network);
Set the network in an uncompiled state, forcing it to recompile at the next simulation step or run (or the network can be recompiled manually with cpg_network_compile)
|
a CpgNetwork |
GSList * cpg_network_get_states (CpgNetwork *network);
Retrieves the list of states. This list is managed internally by the network and should therefore not be changed or freed
|
a CpgNetwork |
Returns : |
a list of CpgState |
GSList * cpg_network_get_links (CpgNetwork *network);
Retrieves the list of links. This list is managed internally by the network and should therefore not be changed or freed
|
a CpgNetwork |
Returns : |
a list of CpgLink |
void cpg_network_run (CpgNetwork *network, gdouble from, gdouble timestep, gdouble to);
Perform a period of simulation. The period is determined by from, timestep and to as described above.
|
a CpgNetwork |
|
the simulation start time |
|
the integration time step to simulate with |
|
the simulation end time |
void cpg_network_step (CpgNetwork *network, gdouble timestep);
Perform one step of simulation given the specified timestep
.
|
a CpgNetwork |
|
the integration timestep |
void cpg_network_reset (CpgNetwork *network);
Reset the CPG network to its original values. This will reset the time to 0 and for all objects in the network will reset all properties to the initial value.
|
a CpgNetwork |
GSList * cpg_network_get_templates (CpgNetwork *network);
Get a list of template names for network
. The names in the list are owned
by the caller and need to be freed accordingly:
g_slist_foreach (templates, (GFunc)g_free, NULL);
|
a CpgNetwork |
Returns : |
a list of template names |
void cpg_network_add_template (CpgNetwork *network, const gchar *name, CpgObject *object);
Adds a new template to the network. Templates can be used to define a basis for constructing new states/links. This can be very useful to keep the xml representation of the network small.
|
a CpgNetwork |
|
the template name |
|
the template object |
CpgObject * cpg_network_get_template (CpgNetwork *network, const gchar *name);
Get a registered template object
|
a CpgNetwork |
|
the template name |
Returns : |
a template object or NULL if the template could not be found
|
void cpg_network_remove_template (CpgNetwork *network, const gchar *name);
Remove a registered template object. Any objects based on this template will become standalone objects.
|
a CpgNetwork |
|
the template name |
CpgObject * cpg_network_add_from_template (CpgNetwork *network, const gchar *name);
Add a new object to the network based on a template. Do not use this for constructing links from templates. To construct links, use cpg_network_add_link_from_template instead.
|
a CpgNetwork |
|
template name |
Returns : |
a new CpgObject. The object is already added to the network |
CpgObject * cpg_network_add_link_from_template (CpgNetwork *network, const gchar *name, CpgObject *from, CpgObject *to);
Add a new link to the network based on a template.
|
a CpgNetwork |
|
template name |
|
a CpgObject |
|
a CpgObject |
Returns : |
a new CpgObject. The object is already added to the network |
void cpg_network_add_function (CpgNetwork *network, CpgFunction *function);
Add a new custom user function to the network.
|
A CpgNetwork |
|
A CpgFunction |
void cpg_network_remove_function (CpgNetwork *network, CpgFunction *function);
Remove a custom user function from the network.
|
A CpgNetwork |
|
A CpgFunction |
GSList * cpg_network_get_functions (CpgNetwork *network);
Get the custom user functions defined in the network.
|
A CpgNetwork |
Returns : |
A GSList of CpgFunction. |
CpgFunction * cpg_network_get_function (CpgNetwork *network, gchar const *name);
Get a custom user function defined in the network.
|
A CpgNetwork |
|
The function name |
Returns : |
A CpgFunction if a function with name could be found, NULL
otherwise
|
GSList * cpg_network_get_integration_state (CpgNetwork *network);
Get the list of properties that need to be integrated.
|
A CpgNetwork |
Returns : |
A GSList of CpgProperty. The list is owned by the network and should not be freed. |
"compiled"
property"compiled" gboolean : Read / Write / Construct
Whether the network is currently compiled
Default value: FALSE
"compile-error"
signalvoid user_function (CpgNetwork *network, CpgCompileError *error, gpointer user_data) : Run Last
Emitted when there is a compile error
|
a CpgNetwork |
|
a CpgCompileError |
|
user data set when the signal handler was connected. |
"reset"
signalvoid user_function (CpgNetwork *network, gpointer user_data) : Run Last
Emitted when the network is reset
|
a CpgNetwork |
|
user data set when the signal handler was connected. |