OpenCores
URL https://opencores.org/ocsvn/w11/w11/trunk

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librtcltools/] [RtclProxyBase.cpp] - Diff between revs 10 and 12

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 10 Rev 12
Line 1... Line 1...
// $Id: RtclProxyBase.cpp 374 2011-03-27 17:02:47Z mueller $
// $Id: RtclProxyBase.cpp 401 2011-07-31 21:02:33Z mueller $
//
//
// Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
// Copyright 2011- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
//
//
// This program is free software; you may redistribute and/or modify it under
// This program is free software; you may redistribute and/or modify it under
// the terms of the GNU General Public License as published by the Free
// the terms of the GNU General Public License as published by the Free
Line 11... Line 11...
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for complete details.
// for complete details.
// 
// 
// Revision History: 
// Revision History: 
// Date         Rev Version  Comment
// Date         Rev Version  Comment
 
// 2011-07-31   401   1.2    add ctor(type,interp,name) for direct usage
 
// 2011-04-23   380   1.1    use boost/function instead of RmethDsc
// 2011-03-05   366   1.0.1  use AppendResultNewLines() in exception catcher
// 2011-03-05   366   1.0.1  use AppendResultNewLines() in exception catcher
// 2011-02-20   363   1.0    Initial version
// 2011-02-20   363   1.0    Initial version
// 2011-02-11   360   0.1    First draft
// 2011-02-11   360   0.1    First draft
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
 
 
/*!
/*!
  \file
  \file
  \version $Id: RtclProxyBase.cpp 374 2011-03-27 17:02:47Z mueller $
  \version $Id: RtclProxyBase.cpp 401 2011-07-31 21:02:33Z mueller $
  \brief   Implemenation of RtclProxyBase.
  \brief   Implemenation of RtclProxyBase.
*/
*/
 
 
#include <stdexcept>
#include <stdexcept>
 
 
Line 48... Line 50...
    fMapMeth(),
    fMapMeth(),
    fInterp(0)
    fInterp(0)
{}
{}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
 
//! FIXME_docs
 
 
 
RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp,
 
                             const char* name)
 
  : fType(type),
 
    fMapMeth(),
 
    fInterp(0)
 
{
 
  CreateObjectCmd(interp, name);
 
}
 
 
 
//------------------------------------------+-----------------------------------
//! Destructor
//! Destructor
 
 
RtclProxyBase::~RtclProxyBase()
RtclProxyBase::~RtclProxyBase()
{
{
  if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this);
  if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this);
  for (mmap_it_t it=fMapMeth.begin(); it!=fMapMeth.end(); it++) {
 
    delete it->second;
 
  }
 
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
Line 74... Line 85...
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 
void RtclProxyBase::AddMeth(const std::string& name,
void RtclProxyBase::AddMeth(const std::string& name, const methfo_t& methfo)
                            RmethDscBase<RtclArgs>* pmeth)
 
{
{
  mmap_ins_t ret = fMapMeth.insert(mmap_val_t(name, pmeth));
  mmap_ins_t ret = fMapMeth.insert(mmap_val_t(name, methfo));
  if (ret.second == false)                  // or use !(ret.second)
  if (ret.second == false)                  // or use !(ret.second)
    throw logic_error(string("RtclProxyBase::AddMeth: duplicate name: ") +
    throw logic_error(string("RtclProxyBase::AddMeth: duplicate name: ") +
                      name);
                      name);
  return;
  return;
}
}
Line 104... Line 114...
//! FIXME_docs
//! FIXME_docs
 
 
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc,
                                Tcl_Obj* const objv[])
                                Tcl_Obj* const objv[])
{
{
  mdsc_t* pmdsc = 0;
  mmap_cit_t it_match;
 
 
  if (objc == 1) {                             // no args
  if (objc == 1) {                             // no args
    mmap_cit_t it = fMapMeth.find("$default"); // default method registered ?
    mmap_cit_t it = fMapMeth.find("$default"); // default method registered ?
    if (it == fMapMeth.end()) {                // if not, complain
    if (it == fMapMeth.end()) {                // if not, complain
      Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
      Tcl_WrongNumArgs(interp, 1, objv, "option ?args?");
      return TCL_ERROR;
      return TCL_ERROR;
    }
    }
    pmdsc = it->second;
    it_match = it;
 
 
  } else {                                     // at least method name given 
  } else {                                     // at least method name given 
    string name(Tcl_GetString(objv[1]));
    string name(Tcl_GetString(objv[1]));
    mmap_cit_t it = fMapMeth.lower_bound(name);
    mmap_cit_t it = fMapMeth.lower_bound(name);
 
 
Line 132... Line 142...
        }
        }
      }
      }
      return TCL_ERROR;
      return TCL_ERROR;
    }
    }
 
 
    pmdsc = it->second;
    it_match = it;
 
 
    // check for ambiguous substring match
    // check for ambiguous substring match
    if (name != it->first) {
    if (name != it->first) {
      mmap_cit_t it1 = it;
      mmap_cit_t it1 = it;
      it1++;
      it1++;
Line 153... Line 163...
      }
      }
    }
    }
  }
  }
 
 
  RtclArgs  args(interp, objc, objv, 2);
  RtclArgs  args(interp, objc, objv, 2);
  return (*pmdsc)(args);
  return (it_match->second)(args);
}
}
 
 
//------------------------------------------+-----------------------------------
//------------------------------------------+-----------------------------------
//! FIXME_docs
//! FIXME_docs
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.