GLIP-Lib
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
Glip::Modules::UniformsLoader Class Reference

Loads and writes a set of uniforms variables values from a file or a string. More...

#include <UniformsLoader.hpp>

Classes

class  Node
 Container structure (filter, pipeline). More...
 
class  Resource
 Resource (variable) of a structure (filter, pipeline). More...
 

Public Types

enum  LoadingFilter {
  LoadAll,
  NewOnly,
  NewOnlySilent,
  ReplaceOnly,
  ReplaceOnlySilent
}
 Flags used for loading data from pipelines, strings or files. More...
 
typedef std::map< const
std::string, Node >
::const_iterator 
NodeConstIterator
 Const iterator over the nodes (refers to a std::pair, use second to access the const UniformsLoader::Node& object).
 
typedef std::map< const
std::string, Node >::iterator 
NodeIterator
 Iterator over the nodes (refers to a std::pair, use second to access the UniformsLoader::Node& object).
 
typedef std::map< const
std::string, Resource >
::const_iterator 
ResourceConstIterator
 Const iterator over the resources (refers to a std::pair, use second to access the const UniformsLoader::Resource& object).
 
typedef std::map< const
std::string, Resource >
::iterator 
ResourceIterator
 Iterator over the resources (refers to a std::pair, use second to access the UniformsLoader::Resource& object).
 

Public Member Functions

 UniformsLoader (void)
 UniformsLoader constructor.
 
 UniformsLoader (const UniformsLoader &cpy)
 UniformsLoader copy constructor. More...
 
void load (std::string source, LoadingFilter loadingFilter=LoadAll, int lineOffset=1)
 Loads a set of uniforms variables for one, or multiple, pipelines. More...
 
void load (Pipeline &pipeline, LoadingFilter loadingFilter=LoadAll)
 Load the set of uniforms variables from a pipeline. More...
 
void load (const UniformsLoader &subLoader, LoadingFilter loadingFilter=LoadAll)
 Load data from another UniformsLoader object. More...
 
bool empty (void) const
 Test if this object has some data loaded. More...
 
void clear (void)
 Clear the full set of data.
 
void clear (const std::string &name)
 Clear the pipeline with the corresponding name. More...
 
bool hasPipeline (const std::string &name) const
 Test if a pipeline has values attached in this UniformsLoader object (knowing its name). More...
 
std::vector< std::string > getPipelinesTypeNames (void) const
 Get the layout names of all the pipelines which have data loaded. More...
 
const NodegetRootNode (const std::string &name) const
 Access the container node of a pipeline type. More...
 
NodegetRootNode (const std::string &name)
 Access the container node of a pipeline type. More...
 
NodeConstIterator rootNodeBegin (void) const
 Get the 'begin' iterator on the nodes list. More...
 
NodeConstIterator rootNodeEnd (void) const
 Get the 'end' iterator on the nodes list. More...
 
NodeIterator rootNodeBegin (void)
 Get the 'begin' iterator on the nodes list. More...
 
NodeIterator rootNodeEnd (void)
 Get the 'end' iterator on the nodes list. More...
 
int applyTo (Pipeline &pipeline, bool forceWrite=true, bool silent=false) const
 Copy the possibly loaded set of uniforms variables to a pipeline (for the corresponding name of the Pipeline instance). More...
 
std::string getCode (void) const
 Return the corresponding code for the current set of variables, for one, or multiple, pipelines. The format is human-readable. More...
 
std::string getCode (const std::string &name) const
 Return the corresponding code of the corresponding pipeline. The format is human-readable. More...
 
void writeToFile (const std::string &filename) const
 Write the corresponding code for the current set of variables, for one, or multiple, pipelines to a file. The format is human-readable. Note : in order to append, you must load the original first. More...
 

Static Public Member Functions

static const char * getKeyword (UniformsLoaderKeyword k)
 Get the actual keyword string. More...
 

Detailed Description

Loads and writes a set of uniforms variables values from a file or a string.

Load, store and manage set of uniforms values for one, or multiple pipelines. The code is set to be human readable :

Example :

PIPELINE:myPipeline
{
FILTER:firstFilter
{
GL_FLOAT:scalar1(1.0)
GL_VEC3:vector1(0.0, -2.0, 3.0)
}
}

Processing example :

// Load values from a current Pipeline, replace existing values :
uniformsLoader.load(mainPipeline);
// Get the corresponding code :
std::string uCode = uniformsLoader.getCode( mainPipeline.getTypeName() );
// Get the code of all the data saved :
std::string uAllCode = uniformsLoader.getCode();
// Save to file :
uniformsLoader.writeToFile("./currentData.uvd");
// Clear all :
uniformsLoader.clear();
// Reload (no replacement, if an element already exists it will raise an exception) :
uniformsLoader.load("./currentData.uvd");
// Apply :
int c = uniformsLoader.applyTo(mainPipeline);
std::cout << c << " variables were loaded." << std::endl;

Note that each UniformsLoader will index the pipelines by their layout name (see AbstractComponentLayout::getLayoutName()). Each can only have one set of pipeline uniform variables per layout name.

Member Enumeration Documentation

Flags used for loading data from pipelines, strings or files.

Enumerator
LoadAll 

Load all the data, append new data, replace existing data.

NewOnly 

Load only new data, throw an Exception if some data already exists.

NewOnlySilent 

Load only new data, ignore data which already exists.

ReplaceOnly 

Replace existing data only, throw an Exception if there is some new data.

ReplaceOnlySilent 

Replace existing data only, ignore new data.

Constructor & Destructor Documentation

UniformsLoader::UniformsLoader ( const UniformsLoader cpy)

UniformsLoader copy constructor.

Parameters
cpyThe object to be copied.

Member Function Documentation

int UniformsLoader::applyTo ( Pipeline pipeline,
bool  forceWrite = true,
bool  silent = false 
) const

Copy the possibly loaded set of uniforms variables to a pipeline (for the corresponding name of the Pipeline instance).

Parameters
pipelineThe pipeline to which the data has to be copied (if relevant).
forceWriteIf set to false, only the variable marked as modified will be loaded (see UniformsLoader::Resource::modified).
silentIf true, no exception will be reported (aside from internal exception).
Returns
The total number of uniforms variables actually copied.
void UniformsLoader::clear ( const std::string &  name)

Clear the pipeline with the corresponding name.

Parameters
nameThe name of the pipeline to be erased.
bool UniformsLoader::empty ( void  ) const

Test if this object has some data loaded.

Returns
True if there is data loaded.
std::string UniformsLoader::getCode ( void  ) const

Return the corresponding code for the current set of variables, for one, or multiple, pipelines. The format is human-readable.

Returns
A standard string containing the structured data.
std::string UniformsLoader::getCode ( const std::string &  name) const

Return the corresponding code of the corresponding pipeline. The format is human-readable.

Parameters
nameThe name of the pipeline to target.
Returns
A standard string containing the structured data. Raise an Exception if no pipeline is found.
const char * UniformsLoader::getKeyword ( UniformsLoaderKeyword  k)
static

Get the actual keyword string.

Parameters
kThe index of the keyword.
Returns
A const pointer to a C-style character string.
std::vector< std::string > UniformsLoader::getPipelinesTypeNames ( void  ) const

Get the layout names of all the pipelines which have data loaded.

Returns
A vector of strings, each one is a known pipeline layout name (see AbstractComponentLayout::getLayoutName()).
const UniformsLoader::Node & UniformsLoader::getRootNode ( const std::string &  name) const

Access the container node of a pipeline type.

Parameters
nameThe layout name of the targeted pipeline.
Returns
A (constant) reference to the UniformsLoader::Node object of the correct layout name. Raise an exception if any error occur.
UniformsLoader::Node & UniformsLoader::getRootNode ( const std::string &  name)

Access the container node of a pipeline type.

Parameters
nameThe layout name of the targeted pipeline.
Returns
A (constant) reference to the UniformsLoader::Node object of the correct layout name. Raise an exception if any error occur.
bool UniformsLoader::hasPipeline ( const std::string &  name) const

Test if a pipeline has values attached in this UniformsLoader object (knowing its name).

Parameters
nameThe name of the pipeline to test (see Component::getName()).
Returns
True if a pipeline with the correct name has values loaded in this UniformsLoader object.
void UniformsLoader::load ( std::string  source,
LoadingFilter  loadingFilter = LoadAll,
int  lineOffset = 1 
)

Loads a set of uniforms variables for one, or multiple, pipelines.

Parameters
sourceEither a filename or directly the source string (in this case it must contain at least one newline character '\n').
loadingFilterSelect a specific method of loading.
lineOffsetSet the line number offset for error reporting.
void UniformsLoader::load ( Pipeline pipeline,
LoadingFilter  loadingFilter = LoadAll 
)

Load the set of uniforms variables from a pipeline.

Parameters
pipelineThe pipeline to extract the data from.
loadingFilterSelect a specific method of loading.

All the pipelines are stored according to their layout name. Only one pipeline per layout name is supported.

void UniformsLoader::load ( const UniformsLoader subLoader,
LoadingFilter  loadingFilter = LoadAll 
)

Load data from another UniformsLoader object.

Parameters
subLoaderOther object.
loadingFilterSelect a specific method of loading.
UniformsLoader::NodeConstIterator UniformsLoader::rootNodeBegin ( void  ) const

Get the 'begin' iterator on the nodes list.

Returns
A UniformsLoader::NodeConstIterator on 'begin'.
UniformsLoader::NodeIterator UniformsLoader::rootNodeBegin ( void  )

Get the 'begin' iterator on the nodes list.

Returns
A UniformsLoader::NodeIterator on 'begin'.
UniformsLoader::NodeConstIterator UniformsLoader::rootNodeEnd ( void  ) const

Get the 'end' iterator on the nodes list.

Returns
A UniformsLoader::NodeConstIterator on 'end'.
UniformsLoader::NodeIterator UniformsLoader::rootNodeEnd ( void  )

Get the 'end' iterator on the nodes list.

Returns
A UniformsLoader::NodeIterator on 'end'.
void UniformsLoader::writeToFile ( const std::string &  filename) const

Write the corresponding code for the current set of variables, for one, or multiple, pipelines to a file. The format is human-readable. Note : in order to append, you must load the original first.

Parameters
filenameThe filename of the file to write to.

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