PLearn 0.1
Public Types | Public Member Functions | Static Public Member Functions | Static Private Member Functions | Private Attributes
PLearn::VMatrixExtensionRegistrar Class Reference

Extension registrar for new file types. More...

#include <getDataSet.h>

Collaboration diagram for PLearn::VMatrixExtensionRegistrar:
Collaboration graph
[legend]

List of all members.

Public Types

typedef VMat(* VMatrixInstantiator )(const PPath &filename)
typedef map< string,
VMatrixExtensionRegistrar
ExtensionMap

Public Member Functions

 VMatrixExtensionRegistrar (const string &file_extension, VMatrixInstantiator instantiation_function, const string &documentation)
const string & documentation () const
 Return the documentation associated with a registrar.

Static Public Member Functions

static const ExtensionMapregisteredExtensions ()
 Return the list of all registered extensions.
static void registerExtension (const VMatrixExtensionRegistrar &new_extension)
 Register a new extension.
static VMatrixInstantiator getInstantiator (const string &file_extension)
 Return the instantiator given an extension, or NULL if not found.

Static Private Member Functions

static ExtensionMapregisteredExtensionsAux ()
 Set of registered extensions.

Private Attributes

string m_file_extension
VMatrixInstantiator m_instantiator
string m_documentation

Detailed Description

Extension registrar for new file types.

If you want to extend getDataSet so that it recognizes new extensions (and constructs the correct type of VMatrix automatically), you should instantiate a static VMatrixExtensionRegistrar object within the .cc of your new VMatrix type. This object will automatically register the new extension with getDataSet, so that when you try to open a file of that extension, the instantiation function is called. For example:

VMatrixExtensionRegistrar( "fancyext", // Note: no leading period &FancyVMatrix::instantiateFromPPath, "Fancy new file format, giving a FancyVMatrix")

This associates files with the ".fancyext" extension with a construction function (that must take a single PPath argument and returns a VMat). The last argument is some documentation.

Definition at line 85 of file getDataSet.h.


Member Typedef Documentation

Definition at line 89 of file getDataSet.h.

Definition at line 88 of file getDataSet.h.


Constructor & Destructor Documentation

PLearn::VMatrixExtensionRegistrar::VMatrixExtensionRegistrar ( const string &  file_extension,
VMatrixInstantiator  instantiation_function,
const string &  documentation 
)

Definition at line 255 of file getDataSet.cc.

References registerExtension().

    : m_file_extension(extension),
      m_instantiator(instantiator),
      m_documentation(doc)
{
    registerExtension(*this);
}

Here is the call graph for this function:


Member Function Documentation

const string& PLearn::VMatrixExtensionRegistrar::documentation ( ) const [inline]

Return the documentation associated with a registrar.

Definition at line 97 of file getDataSet.h.

    {
        return m_documentation;
    }
VMatrixExtensionRegistrar::VMatrixInstantiator PLearn::VMatrixExtensionRegistrar::getInstantiator ( const string &  file_extension) [static]

Return the instantiator given an extension, or NULL if not found.

Definition at line 280 of file getDataSet.cc.

References registeredExtensions().

Referenced by PLearn::getDataSet().

{
    map<string,VMatrixExtensionRegistrar>::const_iterator found =
        registeredExtensions().find(ext);
    if (found == registeredExtensions().end())
        return 0;
    else
        return found->second.m_instantiator;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const ExtensionMap& PLearn::VMatrixExtensionRegistrar::registeredExtensions ( ) [inline, static]

Return the list of all registered extensions.

Definition at line 106 of file getDataSet.h.

Referenced by PLearn::getDataSetHelp(), and getInstantiator().

    {
        return registeredExtensionsAux();
    }

Here is the caller graph for this function:

VMatrixExtensionRegistrar::ExtensionMap & PLearn::VMatrixExtensionRegistrar::registeredExtensionsAux ( ) [static, private]

Set of registered extensions.

Definition at line 292 of file getDataSet.cc.

Referenced by registerExtension().

{
    // Sidestep order-or-static-initialization issue across translation units
    static ExtensionMap extensions;
    return extensions;
}

Here is the caller graph for this function:

void PLearn::VMatrixExtensionRegistrar::registerExtension ( const VMatrixExtensionRegistrar new_extension) [static]

Register a new extension.

Definition at line 265 of file getDataSet.cc.

References PLearn::endl(), m_documentation, m_file_extension, NAMED_LOG, and registeredExtensionsAux().

Referenced by VMatrixExtensionRegistrar().

{
    // If inserting same extension a second time, does NOT override first call
    if (registeredExtensionsAux().insert(
            make_pair(ext.m_file_extension,ext)).second)
    {
        NAMED_LOG("VMatrixExtensionRegistrar")
            << "Registered new VMatrix extension: " << ext.m_file_extension
            << " (" << ext.m_documentation << ")"
            << endl;
    }   
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 121 of file getDataSet.h.

Referenced by registerExtension().

Definition at line 119 of file getDataSet.h.

Referenced by registerExtension().

Definition at line 120 of file getDataSet.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines