PLearn 0.1
Public Types | Public Member Functions | Protected Attributes | Private Member Functions
PLearn::RemoteMethodMap Class Reference

Map for determining a trampoline from a method-name+arity. More...

#include <RemoteMethodMap.h>

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

List of all members.

Public Types

typedef map< pair< string, int >
, PP< RemoteTrampoline > > 
MethodMap
 We map from a method-name:arity pair to a trampoline.

Public Member Functions

 RemoteMethodMap (const RemoteMethodMap *inherited_methods=0)
 Constructor takes an optional pointer to a map of inherited methods (obtained from the base class)
 ~RemoteMethodMap ()
void inherited (const RemoteMethodMap &inherited)
 Establish the pointer to inherited methods.
bool insert (const string &methodname, int arity, PP< RemoteTrampoline > trampoline)
 Add a new method into the map and returns true.
MethodMap::size_type erase (const string &methodname, int arity)
 Remove a method from the map; return the number of elements deleted.
const RemoteTrampolinelookup (const string &methodname, int arity, bool search_inherited=true) const
 Lookup the given method from the map.
const RemoteMethodMapinheritedMethods () const
 Return the base-class method map.
int size () const
MethodMap::const_iterator begin () const
 Return a begin-iterator to the elements.
MethodMap::const_iterator end () const
 Return a end-iterator to the elements.
vector< pair< string, int > > getMethodList () const
 Returns a list of all methods in the given map as pairs of (funtionname, nargs)
vector< string > getMethodPrototypes () const
 Returns a list of the prototypes of all the methods in the given map.
string getMethodHelpText (const string &methodname, int arity=-1) const
 Returns full help on the specified method in the map.
const MethodMapgetMap () const
 Get the method map itself.

Protected Attributes

MethodMap m_methods
 Set of methods at this level.
const RemoteMethodMapm_inherited
 Backpointer to base-class methods.

Private Member Functions

 RemoteMethodMap (const RemoteMethodMap &)
void operator= (const RemoteMethodMap &)

Detailed Description

Map for determining a trampoline from a method-name+arity.

The basic idea is to provide a thin wrapper over a standard-library map with the following features:

Definition at line 72 of file RemoteMethodMap.h.


Member Typedef Documentation

We map from a method-name:arity pair to a trampoline.

Definition at line 76 of file RemoteMethodMap.h.


Constructor & Destructor Documentation

PLearn::RemoteMethodMap::RemoteMethodMap ( const RemoteMethodMap inherited_methods = 0) [inline]

Constructor takes an optional pointer to a map of inherited methods (obtained from the base class)

Definition at line 81 of file RemoteMethodMap.h.

        : m_inherited(inherited_methods)
    { }
PLearn::RemoteMethodMap::~RemoteMethodMap ( )

Definition at line 46 of file RemoteMethodMap.cc.

{ }
PLearn::RemoteMethodMap::RemoteMethodMap ( const RemoteMethodMap ) [private]

Member Function Documentation

MethodMap::const_iterator PLearn::RemoteMethodMap::begin ( ) const [inline]

Return a begin-iterator to the elements.

Definition at line 133 of file RemoteMethodMap.h.

References m_methods.

Referenced by PLearn::HTMLHelpCommand::helpOnClass(), and PLearn::injectPLearnClasses().

    {
        return m_methods.begin();
    }

Here is the caller graph for this function:

MethodMap::const_iterator PLearn::RemoteMethodMap::end ( ) const [inline]

Return a end-iterator to the elements.

Definition at line 139 of file RemoteMethodMap.h.

References m_methods.

Referenced by PLearn::HTMLHelpCommand::helpOnClass(), and PLearn::injectPLearnClasses().

    {
        return m_methods.end();
    }

Here is the caller graph for this function:

RemoteMethodMap::MethodMap::size_type PLearn::RemoteMethodMap::erase ( const string &  methodname,
int  arity 
)

Remove a method from the map; return the number of elements deleted.

Never touches 'inherited_methods'

Definition at line 57 of file RemoteMethodMap.cc.

{
    return m_methods.erase(make_pair(methodname,arity));
}
const MethodMap& PLearn::RemoteMethodMap::getMap ( ) const [inline]

Get the method map itself.

Definition at line 159 of file RemoteMethodMap.h.

References m_methods.

Referenced by PLearn::injectPLearnGlobalFunctions().

    { return m_methods; }

Here is the caller graph for this function:

string PLearn::RemoteMethodMap::getMethodHelpText ( const string &  methodname,
int  arity = -1 
) const

Returns full help on the specified method in the map.

If nargs is >=0 the call will launch an exception if no method with the given name and arity (number of arguments) exists in the map. If nargs is <0 the call will give full help about all registered methods with that name (whatever their arity), or return the string "** No method named ... **"

Definition at line 94 of file RemoteMethodMap.cc.

References PLearn::RemoteTrampoline::documentation(), PLearn::RemoteMethodDoc::getFullHelpText(), and PLERROR.

Referenced by PLearn::HelpSystem::helpOnFunction().

{
    string txt;
    if(arity>=0)
    {
        const RemoteTrampoline* tramp = lookup(methodname, arity, true);
        if(tramp==0)
            PLERROR("RemoteMethodMap contains no method %s with %d arguments",methodname.c_str(), arity);
        txt = tramp->documentation().getFullHelpText();
    }
    else
    {
        RemoteMethodMap::MethodMap::const_iterator it = begin();
        RemoteMethodMap::MethodMap::const_iterator itend = end();
        for(; it!=itend; ++it)
        {
            if(it->first.first==methodname)
                txt += it->second->documentation().getFullHelpText()+"\n";
        }
        if(txt=="")
            txt = "** No method named "+methodname+ " **\n";
    } 
    return txt;
}

Here is the call graph for this function:

Here is the caller graph for this function:

vector< pair< string, int > > PLearn::RemoteMethodMap::getMethodList ( ) const

Returns a list of all methods in the given map as pairs of (funtionname, nargs)

Definition at line 74 of file RemoteMethodMap.cc.

References i, and n.

Referenced by PLearn::HelpSystem::listFunctions().

{
    int n = size();
    vector< pair<string,int> > flist(n);
    RemoteMethodMap::MethodMap::const_iterator it = begin();
    for(int i=0; i<n; ++i, ++it)
        flist[i] = it->first;
    return flist;
}

Here is the caller graph for this function:

vector< string > PLearn::RemoteMethodMap::getMethodPrototypes ( ) const

Returns a list of the prototypes of all the methods in the given map.

Definition at line 84 of file RemoteMethodMap.cc.

References i, and n.

Referenced by PLearn::HelpSystem::listFunctionPrototypes().

{
    int n = size();
    vector<string> prototypes(n);
    RemoteMethodMap::MethodMap::const_iterator it = begin();
    for(int i=0; i<n; ++i, ++it)
        prototypes[i] = it->second->documentation().getPrototypeString();
    return prototypes;
}

Here is the caller graph for this function:

void PLearn::RemoteMethodMap::inherited ( const RemoteMethodMap inherited) [inline]

Establish the pointer to inherited methods.

A typical pattern within a declareMethods() function would be:

  void MyClass::declareMethods(RemoteMethodMap& rmm)
  {
      rmm.inherited(inherited::getRemoteMethodMap());

      // A bunch of declareMethod() here
  }

Definition at line 100 of file RemoteMethodMap.h.

References m_inherited.

Referenced by PLearn::VMatrix::declareMethods(), PLearn::VecStatsCollector::declareMethods(), PLearn::Variable::declareMethods(), PLearn::TreeDBNModule::declareMethods(), PLearn::TransformationLearner::declareMethods(), PLearn::StatsCollector::declareMethods(), PLearn::StackedAutoassociatorsNet::declareMethods(), PLearn::Splitter::declareMethods(), PLearn::RPPath::declareMethods(), PLearn::RBMTrainer::declareMethods(), PLearn::RBMSparse1DMatrixConnection::declareMethods(), PLearn::RBMModule::declareMethods(), PLearn::RBMLayer::declareMethods(), PLearn::RBMConnection::declareMethods(), PLearn::PTester::declareMethods(), PLearn::PLearner::declareMethods(), PLearn::PDistribution::declareMethods(), PLearn::ParentableObject::declareMethods(), PLearn::Optimizer::declareMethods(), PLearn::OnlineLearningModule::declareMethods(), PLearn::Kernel::declareMethods(), PLearn::InferenceRBM::declareMethods(), PLearn::HyperCommand::declareMethods(), PLearn::GaussianizeVMatrix::declareMethods(), PLearn::GaussianDistribution::declareMethods(), PLearn::EmbeddedLearner::declareMethods(), PLearn::DTWKernel::declareMethods(), PLearn::DiverseComponentAnalysis::declareMethods(), PLearn::DeepReconstructorNet::declareMethods(), PLearn::DeepBeliefNet::declareMethods(), and PLearn::Calendar::declareMethods().

Here is the caller graph for this function:

const RemoteMethodMap* PLearn::RemoteMethodMap::inheritedMethods ( ) const [inline]

Return the base-class method map.

Definition at line 122 of file RemoteMethodMap.h.

References m_inherited.

Referenced by PLearn::HTMLHelpCommand::helpOnClass(), and PLearn::injectPLearnClasses().

    {
        return m_inherited;
    }

Here is the caller graph for this function:

bool PLearn::RemoteMethodMap::insert ( const string &  methodname,
int  arity,
PP< RemoteTrampoline trampoline 
)

Add a new method into the map and returns true.

If the method already exists, don't change existing entry and return false. Never touches 'inherited_methods'

Definition at line 49 of file RemoteMethodMap.cc.

Referenced by PLearn::declareFunction(), PLearn::declareMethod(), and PLearn::Object::declareMethods().

{
    return m_methods.insert(make_pair(make_pair(methodname,arity),
                                      trampoline)).second;
}

Here is the caller graph for this function:

const RemoteTrampoline * PLearn::RemoteMethodMap::lookup ( const string &  methodname,
int  arity,
bool  search_inherited = true 
) const

Lookup the given method from the map.

If 'search_inherited' is true inherited methods are recursively looked at as well. Return 0 if not found.

Definition at line 62 of file RemoteMethodMap.cc.

References if().

Referenced by PLearn::Object::call(), PLearn::callFunction(), and PLearn::HelpSystem::helpOnFunctionHTML().

{
    MethodMap::const_iterator it = m_methods.find(make_pair(methodname,arity));
    if (it != m_methods.end())
        return it->second;
    else if (search_inherited && m_inherited)
        return m_inherited->lookup(methodname,arity,search_inherited);
    else
        return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::RemoteMethodMap::operator= ( const RemoteMethodMap ) [private]
int PLearn::RemoteMethodMap::size ( ) const [inline]

Definition at line 127 of file RemoteMethodMap.h.

References m_methods.

Referenced by PLearn::injectPLearnClasses().

    {
        return m_methods.size();
    }

Here is the caller graph for this function:


Member Data Documentation

Backpointer to base-class methods.

Definition at line 164 of file RemoteMethodMap.h.

Referenced by inherited(), and inheritedMethods().

Set of methods at this level.

Definition at line 163 of file RemoteMethodMap.h.

Referenced by begin(), end(), getMap(), and size().


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