PLearn 0.1
RemoteMethodMap.cc
Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // RemoteMethodMap.cc
00004 //
00005 // Copyright (C) 2006 Nicolas Chapados
00006 //
00007 // Redistribution and use in source and binary forms, with or without
00008 // modification, are permitted provided that the following conditions are met:
00009 //
00010 //  1. Redistributions of source code must retain the above copyright
00011 //     notice, this list of conditions and the following disclaimer.
00012 //
00013 //  2. Redistributions in binary form must reproduce the above copyright
00014 //     notice, this list of conditions and the following disclaimer in the
00015 //     documentation and/or other materials provided with the distribution.
00016 //
00017 //  3. The name of the authors may not be used to endorse or promote
00018 //     products derived from this software without specific prior written
00019 //     permission.
00020 //
00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00031 //
00032 // This file is part of the PLearn library. For more information on the PLearn
00033 // library, go to the PLearn Web site at www.plearn.org
00034 
00035 // Authors: Nicolas Chapados
00036 
00039 #include "RemoteMethodMap.h"
00040 
00041 namespace PLearn {
00042 using namespace std;
00043 
00044 //#####  RemoteMethodMap Implementation  ######################################
00045 
00046 RemoteMethodMap::~RemoteMethodMap()
00047 { }
00048 
00049 bool RemoteMethodMap::insert(const string& methodname, int arity,
00050                              PP<RemoteTrampoline> trampoline)
00051 {
00052     return m_methods.insert(make_pair(make_pair(methodname,arity),
00053                                       trampoline)).second;
00054 }
00055 
00056 RemoteMethodMap::MethodMap::size_type
00057 RemoteMethodMap::erase(const string& methodname, int arity)
00058 {
00059     return m_methods.erase(make_pair(methodname,arity));
00060 }
00061 
00062 const RemoteTrampoline* RemoteMethodMap::lookup(const string& methodname, int arity,
00063                                                 bool search_inherited) const
00064 {
00065     MethodMap::const_iterator it = m_methods.find(make_pair(methodname,arity));
00066     if (it != m_methods.end())
00067         return it->second;
00068     else if (search_inherited && m_inherited)
00069         return m_inherited->lookup(methodname,arity,search_inherited);
00070     else
00071         return 0;
00072 }
00073 
00074 vector< pair<string, int> > RemoteMethodMap::getMethodList() const
00075 {
00076     int n = size();
00077     vector< pair<string,int> > flist(n);
00078     RemoteMethodMap::MethodMap::const_iterator it = begin();
00079     for(int i=0; i<n; ++i, ++it)
00080         flist[i] = it->first;
00081     return flist;
00082 }
00083 
00084 vector<string> RemoteMethodMap::getMethodPrototypes() const
00085 {
00086     int n = size();
00087     vector<string> prototypes(n);
00088     RemoteMethodMap::MethodMap::const_iterator it = begin();
00089     for(int i=0; i<n; ++i, ++it)
00090         prototypes[i] = it->second->documentation().getPrototypeString();
00091     return prototypes;
00092 }
00093 
00094 string RemoteMethodMap::getMethodHelpText(const string& methodname, int arity) const
00095 {
00096     string txt;
00097     if(arity>=0)
00098     {
00099         const RemoteTrampoline* tramp = lookup(methodname, arity, true);
00100         if(tramp==0)
00101             PLERROR("RemoteMethodMap contains no method %s with %d arguments",methodname.c_str(), arity);
00102         txt = tramp->documentation().getFullHelpText();
00103     }
00104     else
00105     {
00106         RemoteMethodMap::MethodMap::const_iterator it = begin();
00107         RemoteMethodMap::MethodMap::const_iterator itend = end();
00108         for(; it!=itend; ++it)
00109         {
00110             if(it->first.first==methodname)
00111                 txt += it->second->documentation().getFullHelpText()+"\n";
00112         }
00113         if(txt=="")
00114             txt = "** No method named "+methodname+ " **\n";
00115     } 
00116     return txt;
00117 }
00118 
00119 } // end of namespace PLearn
00120 
00121 
00122 /*
00123   Local Variables:
00124   mode:c++
00125   c-basic-offset:4
00126   c-file-style:"stroustrup"
00127   c-file-offsets:((innamespace . 0)(inline-open . 0))
00128   indent-tabs-mode:nil
00129   fill-column:79
00130   End:
00131 */
00132 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines