URL
https://opencores.org/ocsvn/w11/w11/trunk
Subversion Repositories w11
Compare Revisions
- This comparison shows the changes necessary to convert path
/w11/tags/w11a_V0.6/tools/src/librtcltools
- from Rev 22 to Rev 24
- ↔ Reverse comparison
Rev 22 → Rev 24
/RtclOPtr.hpp
0,0 → 1,55
// $Id: RtclOPtr.hpp 521 2013-05-20 22:16:45Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-05-20 521 1.0.1 declare ctor(Tcl_Obj*) as explicit |
// 2011-02-20 363 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
|
/*! |
\file |
\version $Id: RtclOPtr.hpp 521 2013-05-20 22:16:45Z mueller $ |
\brief Declaration of class RtclOPtr. |
*/ |
|
#ifndef included_Retro_RtclOPtr |
#define included_Retro_RtclOPtr 1 |
|
#include "tcl.h" |
|
namespace Retro { |
|
class RtclOPtr { |
public: |
RtclOPtr(); |
explicit RtclOPtr(Tcl_Obj* pobj); |
RtclOPtr(const RtclOPtr& rhs); |
~RtclOPtr(); |
|
operator Tcl_Obj*() const; |
bool operator !() const; |
RtclOPtr& operator=(const RtclOPtr& rhs); |
RtclOPtr& operator=(Tcl_Obj* pobj); |
|
protected: |
Tcl_Obj* fpObj; //!< pointer to tcl object |
}; |
|
} // end namespace Retro |
|
// implementation all inline |
#include "RtclOPtr.ipp" |
|
#endif |
/RtclNameSet.cpp
0,0 → 1,137
// $Id: RtclNameSet.cpp 521 2013-05-20 22:16:45Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-05-19 521 1.1 add CheckMatch() |
// 2013-02-03 481 1.0.1 use Rexception |
// 2011-02-20 363 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclNameSet.cpp 521 2013-05-20 22:16:45Z mueller $ |
\brief Implemenation of RtclNameSet. |
*/ |
|
// debug |
#include <iostream> |
|
#include "RtclNameSet.hpp" |
|
#include "librtools/Rexception.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclNameSet |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
typedef std::pair<RtclNameSet::nset_it_t, bool> nset_ins_t; |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
RtclNameSet::RtclNameSet() |
: fSet() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclNameSet::RtclNameSet(const std::string& nset) |
: fSet() |
{ |
size_t ibeg=0; |
while (true) { |
size_t iend = nset.find_first_of('|', ibeg); |
if (iend-ibeg > 0) { |
string name(nset, ibeg, iend-ibeg); |
nset_ins_t ret = fSet.insert(name); |
if (ret.second == false) // or use !(ret.second) |
throw Rexception("RtclNameSet::<ctor>", "Bad args: " + |
string("duplicate name '") + name + |
"' in set '" + nset + "'"); |
} |
if (iend == string::npos) break; |
ibeg = iend+1; |
} |
} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclNameSet::~RtclNameSet() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclNameSet::Check(Tcl_Interp* interp, std::string& rval, |
const std::string& tval) const |
{ |
return CheckMatch(interp, rval, tval, true) > 0; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
// irc = 1 -> match |
// 0 -> ambiguous match --> tcl err |
// -1 -> no match --> tcl err if misserr |
|
int RtclNameSet::CheckMatch(Tcl_Interp* interp, std::string& rval, |
const std::string& tval, bool misserr) const |
{ |
rval.clear(); |
nset_cit_t it = fSet.lower_bound(tval); |
|
// no leading substring match |
if (it==fSet.end() || tval!=it->substr(0,tval.length())) { |
if (misserr) { |
Tcl_AppendResult(interp, "-E: bad option '", tval.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (nset_cit_t it1=fSet.begin(); it1!=fSet.end(); it1++) { |
Tcl_AppendResult(interp, delim, it1->c_str(), NULL); |
delim = ","; |
} |
} |
return -1; |
} |
|
// check for ambiguous substring match |
if (tval != *it) { |
nset_cit_t it1 = it; |
it1++; |
if (it1!=fSet.end() && tval==it1->substr(0,tval.length())) { |
Tcl_AppendResult(interp, "-E: ambiguous option '", tval.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (it1=it; it1!=fSet.end() && |
tval==it1->substr(0,tval.length()); it1++) { |
Tcl_AppendResult(interp, delim, it1->c_str(), NULL); |
delim = ","; |
} |
return 0; |
} |
} |
|
rval = *it; |
return 1; |
} |
|
} // end namespace Retro |
/RtclNameSet.hpp
0,0 → 1,62
// $Id: RtclNameSet.hpp 521 2013-05-20 22:16:45Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-05-19 521 1.1 add CheckMatch() |
// 2011-02-20 363 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
|
/*! |
\file |
\version $Id: RtclNameSet.hpp 521 2013-05-20 22:16:45Z mueller $ |
\brief Declaration of class RtclNameSet. |
*/ |
|
#ifndef included_Retro_RtclNameSet |
#define included_Retro_RtclNameSet 1 |
|
#include "tcl.h" |
|
#include <string> |
#include <set> |
|
#include "RtclNameSet.hpp" |
|
namespace Retro { |
|
class RtclNameSet { |
public: |
typedef std::set<std::string> nset_t; |
typedef nset_t::iterator nset_it_t; |
typedef nset_t::const_iterator nset_cit_t; |
|
RtclNameSet(); |
RtclNameSet(const std::string& nset); |
~RtclNameSet(); |
|
bool Check(Tcl_Interp* interp, std::string& rval, |
const std::string& tval) const; |
int CheckMatch(Tcl_Interp* interp, std::string& rval, |
const std::string& tval, bool misserr) const; |
|
protected: |
nset_t fSet; |
}; |
|
} // end namespace Retro |
|
//#include "RtclNameSet.ipp" |
|
#endif |
/Makefile
0,0 → 1,64
# $Id: Makefile 529 2013-08-02 17:15:43Z mueller $ |
# |
# Revision History: |
# Date Rev Version Comment |
# 2013-02-01 479 1.1.2 use checkpath_cpp.mk |
# 2012-12-24 464 1.1.1 add TCLINC |
# 2011-07-31 401 1.1 rename realclean->distclean |
# 2011-07-01 386 1.0.1 add BOOSTINC |
# 2011-02-11 360 1.0 Initial version |
#--- |
# |
# Name of the sharable library |
# |
SONAME = rtcltools |
SOMAJV = 1 |
SOMINV = 0 |
# |
# Compile and Link search paths |
# |
include ../checkpath_cpp.mk |
# |
INCLFLAGS = -I${RETROBASE}/tools/src -I${TCLINC} -I${BOOSTINC} |
LDLIBS = -L${RETROBASE}/tools/lib -lrtools |
# |
# Object files to be included |
# |
OBJ_all = Rtcl.o RtclArgs.o RtclClassBase.o RtclContext.o |
OBJ_all += RtclNameSet.o RtclCmdBase.o RtclProxyBase.o RtclStats.o |
OBJ_all += RtclGetBase.o RtclGetList.o RtclSetBase.o RtclSetList.o |
# |
DEP_all = $(OBJ_all:.o=.dep) |
# |
#- generic part ---------------------------------------------------------------- |
# |
SOFILE = lib$(SONAME).so |
SOFILEV = lib$(SONAME).so.$(SOMAJV) |
SOFILEVV = lib$(SONAME).so.$(SOMAJV).$(SOMINV) |
# |
include $(RETROBASE)/tools/make/generic_cpp.mk |
include $(RETROBASE)/tools/make/generic_dep.mk |
include $(RETROBASE)/tools/make/generic_so.mk |
include $(RETROBASE)/tools/make/dontincdep.mk |
# |
# The magic auto-dependency include |
# |
ifndef DONTINCDEP |
include $(DEP_all) |
endif |
# |
# cleanup phonies: |
# |
.PHONY : clean cleandep distclean |
clean : |
@ rm -f $(OBJ_all) |
@ echo "Object files removed" |
# |
cleandep : |
@ rm -f $(DEP_all) |
@ echo "Dependency files removed" |
# |
distclean : clean cleandep |
@ rm -f $(SOPATH)/lib$(SONAME).a $(SOPATH)/lib$(SONAME).so* |
@ echo "Libraries removed" |
# |
/RtclArgs.cpp
0,0 → 1,588
// $Id: RtclArgs.cpp 521 2013-05-20 22:16:45Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-05-19 521 1.0.7 add NextSubOpt() method, pass optset's as const |
// 2013-02-12 487 1.0.6 add CurrentArg() method |
// 2013-02-03 481 1.0.5 use Rexception |
// 2011-03-26 373 1.0.4 add GetArg(float/double) |
// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>); NextOpt clear NOptMiss |
// 2011-03-06 367 1.0.2 add Config() methods; |
// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), SetResult(); |
// add GetArg(Tcl_Obj), PeekArgString(); |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclArgs.cpp 521 2013-05-20 22:16:45Z mueller $ |
\brief Implemenation of RtclArgs. |
*/ |
|
//debug |
#include <iostream> |
|
#include <ctype.h> |
#include <stdarg.h> |
|
#include "RtclArgs.hpp" |
|
#include "Rtcl.hpp" |
#include "librtools/Rexception.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclArgs |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
RtclArgs::RtclArgs() |
: fpInterp(0), |
fObjc(0), |
fObjv(0), |
fNDone(0), |
fNOptMiss(0), |
fNConfigRead(0), |
fOptErr(false), |
fArgErr(false) |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclArgs::RtclArgs(Tcl_Interp* interp, int objc, Tcl_Obj* const objv[], |
size_t nskip) |
: fpInterp(interp), |
fObjc((size_t)objc), |
fObjv(objv), |
fNDone((nskip<=(size_t)objc) ? nskip : (size_t)objc), |
fNOptMiss(0), |
fNConfigRead(0), |
fOptErr(false), |
fArgErr(false) |
{ |
if (objc < 0) |
throw Rexception("RtclArgs::<ctor>","Bad args: objc must be >= 0"); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclArgs::RtclArgs(const RtclArgs& rhs) |
: fpInterp(rhs.fpInterp), |
fObjc(rhs.fObjc), |
fObjv(rhs.fObjv), |
fNDone(rhs.fNDone), |
fNOptMiss(rhs.fNOptMiss), |
fOptErr(rhs.fOptErr), |
fArgErr(rhs.fArgErr) |
{} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclArgs::~RtclArgs() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* RtclArgs::Objv(size_t ind) const |
{ |
if (ind >= (size_t)fObjc) |
throw Rexception("RtclArgs::Objv()","Bad args: index out-of-range"); |
return fObjv[ind]; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, Tcl_Obj*& pval) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
pval = pobj; |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, const char*& val) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
val = Tcl_GetString(pobj); |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, std::string& val) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
val = Tcl_GetString(pobj); |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, int8_t& val, int8_t min, int8_t max) |
{ |
int32_t val32 = (int32_t)val; |
bool ret = GetArg(name, val32, (int32_t)min, (int32_t)max); |
val = (int8_t) val32; |
return ret; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, uint8_t& val, uint8_t max, uint8_t min) |
{ |
uint32_t val32 = (uint32_t)val; |
bool ret = GetArg(name, val32, (uint32_t)max, (uint32_t)min); |
val = (uint8_t) val32; |
return ret; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, int16_t& val, int16_t min, int16_t max) |
{ |
int32_t val32 = (int32_t)val; |
bool ret = GetArg(name, val32, (int32_t)min, (int32_t)max); |
val = (int16_t) val32; |
return ret; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, uint16_t& val, uint16_t max, |
uint16_t min) |
{ |
uint32_t val32 = (uint32_t)val; |
bool ret = GetArg(name, val32, (uint32_t)max, (uint32_t)min); |
val = (uint16_t) val32; |
return ret; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, int32_t& val, int32_t min, int32_t max) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
int objval; |
if (Tcl_GetIntFromObj(fpInterp, pobj, &objval) != TCL_OK) return false; |
if (objval < min || objval > max) { |
ostringstream sos; |
sos << "-E: value '" << objval << "' for '" << name << "' out of range " |
<< min << "..." << max; |
AppendResult(sos); |
return false; |
} |
val = (int32_t) objval; |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, uint32_t& val, uint32_t max, |
uint32_t min) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
int objval; |
if (Tcl_GetIntFromObj(fpInterp, pobj, &objval) != TCL_OK) return false; |
unsigned int objuval = objval; |
if (objuval < min || objuval > max) { |
ostringstream sos; |
sos << "-E: value '" << objuval << "' for '" << name << "' out of range " |
<< min << "..." << max; |
AppendResult(sos); |
return false; |
} |
val = (uint32_t) objval; |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, float& val, float min, float max) |
{ |
double vald = (double)val; |
bool ret = GetArg(name, vald, (double)max, (double)min); |
val = (float) vald; |
return ret; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, double& val, double min, double max) |
{ |
Tcl_Obj* pobj; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
double objval; |
if (Tcl_GetDoubleFromObj(fpInterp, pobj, &objval) != TCL_OK) return false; |
if (objval < min || objval > max) { |
ostringstream sos; |
sos << "-E: value '" << objval << "' for '" << name << "' out of range " |
<< min << "..." << max; |
AppendResult(sos); |
return false; |
} |
val = objval; |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, std::vector<uint8_t>& val, |
size_t lmin, size_t lmax) |
{ |
int objc = 0; |
Tcl_Obj** objv = 0; |
if (!NextArgList(name, objc, objv, lmin, lmax)) return false; |
if (objv==0) return true; |
|
val.clear(); |
val.reserve(objc); |
|
for (int i=0; i<objc; i++) { |
int ival; |
if (Tcl_GetIntFromObj(fpInterp, objv[i], &ival) != TCL_OK) return false; |
int ivalmsb = ival>>8; |
if (ivalmsb != 0 && ivalmsb != -1) { |
ostringstream sos; |
sos << "-E: list element '" << Tcl_GetString(objv[i]) |
<< "' for '" << name |
<< "' out of range " << "0...0xff"; |
AppendResult(sos); |
return false; |
} |
val.push_back((uint8_t)ival); |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::GetArg(const char* name, std::vector<uint16_t>& val, |
size_t lmin, size_t lmax) |
{ |
int objc = 0; |
Tcl_Obj** objv = 0; |
if (!NextArgList(name, objc, objv, lmin, lmax)) return false; |
if (objv==0) return true; |
|
val.clear(); |
val.reserve(objc); |
|
for (int i=0; i<objc; i++) { |
int ival; |
if (Tcl_GetIntFromObj(fpInterp, objv[i], &ival) != TCL_OK) return false; |
int ivalmsb = ival>>16; |
if (ivalmsb != 0 && ivalmsb != -1) { |
ostringstream sos; |
sos << "-E: list element '" << Tcl_GetString(objv[i]) |
<< "' for '" << name |
<< "' out of range " << "0...0xffff"; |
AppendResult(sos); |
return false; |
} |
val.push_back((uint16_t)ival); |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::Config(const char* name, std::string& val) |
{ |
ConfigNameCheck(name); |
string tmp = val; |
if (!GetArg(name, tmp)) return false; |
if (fNOptMiss == 0) { // config write |
val = tmp; |
} else { // config read |
if (!ConfigReadCheck()) return false; |
SetResult(Tcl_NewStringObj(val.data(), val.length())); |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::Config(const char* name, uint32_t& val, uint32_t max, |
uint32_t min) |
{ |
ConfigNameCheck(name); |
uint32_t tmp = val; |
if (!GetArg(name, tmp, max, min)) return false; |
if (fNOptMiss == 0) { // config write |
val = tmp; |
} else { // config read |
if (!ConfigReadCheck()) return false; |
SetResult(Tcl_NewIntObj((int)val)); |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::NextOpt(std::string& val) |
{ |
fNOptMiss = 0; |
val.clear(); |
fOptErr = false; |
|
if (fNDone == fObjc) return false; |
|
const char* str = PeekArgString(0); |
|
if (str[0]=='-' && str[1] && !isdigit(str[1])) { |
fNDone += 1; |
// '--' seen (eat it, and say no Opt's found) |
if (str[1]=='-' && str[2]==0) { |
return false; |
} |
val = str; |
return true; |
} |
return false; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::NextOpt(std::string& val, const RtclNameSet& optset) |
{ |
val.clear(); |
string opt; |
if (!NextOpt(opt) || opt.empty()) return false; |
|
fOptErr = !optset.Check(fpInterp, val, opt); |
return !fOptErr; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
// irc = 1 -> match |
// 0 -> ambiguous match --> tcl err |
// -1 -> no match --> no tcl err |
|
int RtclArgs::NextSubOpt(std::string& val, const RtclNameSet& optset) |
{ |
val.clear(); |
fNOptMiss = 0; |
fOptErr = false; |
|
if (fNDone == fObjc) return -1; |
|
const char* str = PeekArgString(0); |
|
// does next arg look like an option |
if (str[0]=='-' && str[1] && str[1]!='-' && !isdigit(str[1])) { |
// and matches one of optset |
int irc = optset.CheckMatch(fpInterp, val, string(str), false); |
if (irc >= 0) { |
fNDone += 1; |
fOptErr = (irc == 0); |
return irc; |
} |
} |
return -1; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* RtclArgs::CurrentArg() const |
{ |
if (fNDone == 0) |
throw Rexception("RtclArgs::CurrentArg()", |
"Bad state: no argument processed yet"); |
|
return fObjv[fNDone-1]; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::AllDone() |
{ |
if (fArgErr || fOptErr) return false; |
if (fNDone < fObjc) { |
AppendResult("-E: superfluous arguments, first one '", |
Tcl_GetString(fObjv[fNDone]), "'", NULL); |
return false; |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
const char* RtclArgs::PeekArgString(int rind) const |
{ |
int ind = fNDone + rind; |
if (ind < 0 || ind >= (int)fObjc) return ""; |
return Tcl_GetString(fObjv[ind]); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclArgs::AppendResult(const char* str, ...) |
{ |
Tcl_AppendResult(fpInterp, str, NULL); |
va_list ap; |
va_start (ap, str); |
Tcl_AppendResultVA(fpInterp, ap); |
va_end (ap); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclArgs::AppendResultLines(const std::string& str) |
{ |
Rtcl::AppendResultNewLines(fpInterp); |
|
if (str.length()>0 && str[str.length()-1]=='\n') { |
Tcl_AppendResult(fpInterp, str.substr(0,str.length()-1).c_str(), NULL); |
} else { |
Tcl_AppendResult(fpInterp, str.c_str(), NULL); |
} |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::NextArg(const char* name, Tcl_Obj*& pobj) |
{ |
pobj = 0; |
|
bool isopt = name[0] == '?'; |
bool isoptopt = isopt && (name[1] == '?'); |
|
if (!isopt) fNOptMiss = 0; |
|
if (fNDone == fObjc) { |
if (!isopt) { |
AppendResult("-E: required argument '", name, "' missing", NULL); |
fArgErr = true; |
return false; |
} |
fNOptMiss += 1; |
return true; |
} |
|
// if %% arg peek in next arg and check that it's not an option |
if (isoptopt) { |
const char* nval = Tcl_GetString(fObjv[fNDone]); |
if (nval[0]=='-' && nval[1] && isalpha(nval[1])) { |
fNOptMiss += 1; |
return true; |
} |
} |
|
pobj = fObjv[fNDone++]; |
|
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::NextArgList(const char* name, int& objc, Tcl_Obj**& objv, |
size_t lmin, size_t lmax) |
{ |
objc = 0; |
objv = 0; |
Tcl_Obj* pobj = 0; |
if (!NextArg(name, pobj)) return false; |
if (pobj==0) return true; |
|
if (Tcl_ListObjGetElements(fpInterp, pobj, &objc, &objv) != TCL_OK) { |
return false; |
} |
|
if ((size_t)objc < lmin || (size_t)objc > lmax) { |
ostringstream sos; |
sos << "-E: list length '" << objc << "' for '" << name << "' out of range " |
<< lmin << "..." << lmax; |
AppendResult(sos); |
return false; |
} |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclArgs::ConfigNameCheck(const char* name) |
{ |
if (name==0 || name[0]!='?' || name[1]!='?') |
throw Rexception("RtclArgs::Config()","Bad args: name must start with ??"); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclArgs::ConfigReadCheck() |
{ |
if (fNConfigRead != 0) { |
SetResult(Tcl_NewObj()); |
AppendResult("-E: only one config read allowed per command, '", |
PeekArgString(-1), "' is second", NULL); |
return false; |
} |
fNConfigRead += 1; |
return true; |
} |
|
} // end namespace Retro |
/RtclArgs.hpp
0,0 → 1,161
// $Id: RtclArgs.hpp 521 2013-05-20 22:16:45Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-05-19 521 1.0.9 add NextSubOpt() method, pass optset's as const |
// 2013-03-05 495 1.0.8 add SetResult(bool) |
// 2013-03-02 494 1.0.7 add Quit() method |
// 2013-02-12 487 1.0.6 add CurrentArg() method |
// 2013-02-01 479 1.0.5 add Objv() method |
// 2011-03-26 373 1.0.4 add GetArg(flt/dbl), SetResult(str,sos,int,dbl) |
// 2011-03-13 369 1.0.3 add GetArg(vector<unit8_t>) |
// 2011-03-06 367 1.0.2 add min to GetArg(unsigned); add Config() methods; |
// 2011-03-05 366 1.0.1 fObjc,fNDone now size_t; add NDone(), NOptMiss(); |
// add SetResult(), GetArg(Tcl_Obj), PeekArgString(); |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-06 359 0.1 First draft |
// --------------------------------------------------------------------------- |
|
|
/*! |
\file |
\version $Id: RtclArgs.hpp 521 2013-05-20 22:16:45Z mueller $ |
\brief Declaration of class RtclArgs. |
*/ |
|
#ifndef included_Retro_RtclArgs |
#define included_Retro_RtclArgs 1 |
|
#include "tcl.h" |
|
#include <cstddef> |
#include <vector> |
#include <limits> |
#include <sstream> |
|
#include "RtclNameSet.hpp" |
|
namespace Retro { |
|
class RtclArgs { |
public: |
|
const static int8_t int8_min = 0xff; |
const static int8_t int8_max = 0x7f; |
const static uint8_t uint8_max = 0xff; |
const static int16_t int16_min = 0xffff; |
const static int16_t int16_max = 0x7fff; |
const static uint16_t uint16_max = 0xffff; |
const static int32_t int32_min = 0xffffffff; |
const static int32_t int32_max = 0x7fffffff; |
const static uint32_t uint32_max = 0xffffffff; |
|
RtclArgs(); |
RtclArgs(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[], size_t nskip=1); |
RtclArgs(const RtclArgs& rhs); |
~RtclArgs(); |
|
Tcl_Interp* Interp() const; |
int Objc() const; |
Tcl_Obj* const * Objv() const; |
Tcl_Obj* Objv(size_t ind) const; |
|
bool GetArg(const char* name, Tcl_Obj*& pval); |
|
bool GetArg(const char* name, const char*& val); |
bool GetArg(const char* name, std::string& val); |
|
bool GetArg(const char* name, int8_t& val, |
int8_t min=int8_min, int8_t max=int8_max); |
bool GetArg(const char* name, uint8_t& val, |
uint8_t max=uint8_max, uint8_t min=0); |
bool GetArg(const char* name, int16_t& val, |
int16_t min=int16_min, int16_t max=int16_max); |
bool GetArg(const char* name, uint16_t& val, |
uint16_t max=uint16_max, uint16_t min=0); |
bool GetArg(const char* name, int32_t& val, |
int32_t min=int32_min, int32_t max=int32_max); |
bool GetArg(const char* name, uint32_t& val, |
uint32_t max=uint32_max, uint32_t min=0); |
|
bool GetArg(const char* name, float& val, |
float min=-1.e30, float max=+1.e30); |
bool GetArg(const char* name, double& val, |
double min=-1.e30, double max=+1.e30); |
|
bool GetArg(const char* name, std::vector<uint8_t>& val, |
size_t lmin=0, size_t lmax=uint32_max); |
bool GetArg(const char* name, std::vector<uint16_t>& val, |
size_t lmin=0, size_t lmax=uint32_max); |
|
bool Config(const char* name, std::string& val); |
bool Config(const char* name, uint32_t& val, |
uint32_t max=uint32_max, uint32_t min=0); |
|
bool NextOpt(std::string& val); |
bool NextOpt(std::string& val, const RtclNameSet& optset); |
int NextSubOpt(std::string& val, const RtclNameSet& optset); |
bool OptValid() const; |
|
Tcl_Obj* CurrentArg() const; |
|
bool AllDone(); |
size_t NDone() const; |
size_t NOptMiss() const; |
|
const char* PeekArgString(int rind) const; |
|
void SetResult(const std::string& str); |
void SetResult(std::ostringstream& sos); |
void SetResult(bool val); |
void SetResult(int val); |
void SetResult(double val); |
void SetResult(Tcl_Obj* pobj); |
|
void AppendResult(const char* str, ...); |
void AppendResult(const std::string& str); |
void AppendResult(std::ostringstream& sos); |
void AppendResultLines(const std::string& str); |
void AppendResultLines(std::ostringstream& sos); |
|
int Quit(const std::string& str); |
|
Tcl_Obj* operator[](size_t ind) const; |
|
protected: |
bool NextArg(const char* name, Tcl_Obj*& pobj); |
bool NextArgList(const char* name, int& objc, |
Tcl_Obj**& objv, size_t lmin=0, |
size_t lmax=uint32_max); |
void ConfigNameCheck(const char* name); |
bool ConfigReadCheck(); |
|
protected: |
Tcl_Interp* fpInterp; //!< pointer to tcl interpreter |
size_t fObjc; //!< original args count |
Tcl_Obj* const * fObjv; //!< original args vector |
size_t fNDone; //!< number of processed args |
size_t fNOptMiss; //!< number of missed optional args |
size_t fNConfigRead; //!< number of read mode config's |
bool fOptErr; //!< option processing error flag |
bool fArgErr; //!< argument processing error flag |
|
}; |
|
} // end namespace Retro |
|
#include "RtclArgs.ipp" |
|
#endif |
/RtclGetList.cpp
0,0 → 1,117
// $Id: RtclGetList.cpp 516 2013-05-05 21:24:52Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGetList.cpp 516 2013-05-05 21:24:52Z mueller $ |
\brief Implemenation of class RtclGetList. |
*/ |
|
#include <iostream> |
|
#include "librtools/Rexception.hpp" |
|
#include "RtclGet.hpp" |
#include "RtclGetList.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclGetList |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclGetList::RtclGetList() |
: fMap() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclGetList::~RtclGetList() |
{ |
for (map_cit_t it=fMap.begin(); it != fMap.end(); it++) { |
delete (it->second); |
} |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclGetList::Add(const std::string& name, RtclGetBase* pget) |
{ |
typedef std::pair<Retro::RtclGetList::map_it_t, bool> map_ins_t; |
map_ins_t ret = fMap.insert(map_val_t(name, pget)); |
if (ret.second == false) |
throw Rexception("RtclGetList::Add:", |
string("Bad args: duplicate name: '") + name + "'"); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclGetList::M_get(RtclArgs& args) |
{ |
string pname; |
if (!args.GetArg("pname", pname)) return TCL_ERROR; |
|
Tcl_Interp* interp = args.Interp(); |
map_cit_t it = fMap.lower_bound(pname); |
|
// complain if not found |
if (it == fMap.end() || pname != it->first.substr(0,pname.length())) { |
Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (map_cit_t it1=fMap.begin(); it1!=fMap.end(); it1++) { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
return TCL_ERROR; |
} |
|
// check for ambiguous substring match |
map_cit_t it1 = it; |
it1++; |
if (it1!=fMap.end() && pname==it1->first.substr(0,pname.length())) { |
Tcl_AppendResult(interp, "-E: ambiguous property name '", pname.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (it1=it; it1!=fMap.end() && |
pname==it1->first.substr(0,pname.length()); it1++) { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
|
return TCL_ERROR; |
} |
|
if (!args.AllDone()) return TCL_ERROR; |
|
args.SetResult((it->second)->operator()()); |
return TCL_OK; |
} |
|
} // end namespace Retro |
/RtclSetList.cpp
0,0 → 1,126
// $Id: RtclSetList.cpp 516 2013-05-05 21:24:52Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSetList.cpp 516 2013-05-05 21:24:52Z mueller $ |
\brief Implemenation of class RtclSetList. |
*/ |
|
#include <iostream> |
|
#include "librtools/Rexception.hpp" |
|
#include "RtclSet.hpp" |
#include "RtclSetList.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclSetList |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclSetList::RtclSetList() |
: fMap() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclSetList::~RtclSetList() |
{ |
for (map_cit_t it=fMap.begin(); it != fMap.end(); it++) { |
delete (it->second); |
} |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclSetList::Add(const std::string& name, RtclSetBase* pset) |
{ |
typedef std::pair<Retro::RtclSetList::map_it_t, bool> map_ins_t; |
map_ins_t ret = fMap.insert(map_val_t(name, pset)); |
if (ret.second == false) |
throw Rexception("RtclSetList::Add:", |
string("Bad args: duplicate name: '") + name + "'"); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclSetList::M_set(RtclArgs& args) |
{ |
string pname; |
if (!args.GetArg("pname", pname)) return TCL_ERROR; |
|
Tcl_Interp* interp = args.Interp(); |
map_cit_t it = fMap.lower_bound(pname); |
|
// complain if not found |
if (it == fMap.end() || pname != it->first.substr(0,pname.length())) { |
Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (map_cit_t it1=fMap.begin(); it1!=fMap.end(); it1++) { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
return TCL_ERROR; |
} |
|
// check for ambiguous substring match |
map_cit_t it1 = it; |
it1++; |
if (it1!=fMap.end() && pname==it1->first.substr(0,pname.length())) { |
Tcl_AppendResult(interp, "-E: ambiguous property name '", pname.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (it1=it; it1!=fMap.end() && |
pname==it1->first.substr(0,pname.length()); it1++) { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
|
return TCL_ERROR; |
} |
|
Tcl_Obj* pobj; |
if (!args.GetArg("val", pobj)) return TCL_ERROR; |
if (!args.AllDone()) return TCL_ERROR; |
|
try { |
(it->second)->operator()(args); |
} catch (Rexception& e) { |
Tcl_AppendResult(args.Interp(), ", ", e.ErrMsg().Text().c_str(), NULL); |
} catch (exception& e) { |
Tcl_AppendResult(args.Interp(), " -E: ", e.what(), NULL); |
} |
|
return TCL_OK; |
} |
|
} // end namespace Retro |
/RtclCmdBase.cpp
0,0 → 1,140
// $Id: RtclCmdBase.cpp 516 2013-05-05 21:24:52Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-10 485 1.0.2 add static const defs |
// 2013-02-05 483 1.0.1 remove 'unknown specified, full match only' logic |
// 2013-02-02 480 1.0 Initial version (refactored out from ProxyBase) |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclCmdBase.cpp 516 2013-05-05 21:24:52Z mueller $ |
\brief Implemenation of RtclCmdBase. |
*/ |
|
#include "RtclCmdBase.hpp" |
|
#include "librtools/Rexception.hpp" |
#include "Rtcl.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclCmdBase |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
typedef std::pair<RtclCmdBase::mmap_it_t, bool> mmap_ins_t; |
|
//------------------------------------------+----------------------------------- |
// constants definitions |
|
const int RtclCmdBase::kOK; |
const int RtclCmdBase::kERR; |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclCmdBase::RtclCmdBase() |
: fMapMeth() |
{} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclCmdBase::~RtclCmdBase() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclCmdBase::DispatchCmd(RtclArgs& args) |
{ |
mmap_cit_t it_match; |
|
Tcl_Interp* interp = args.Interp(); |
|
// no method name given |
if (args.Objc() <= 1) { // no args |
it_match = fMapMeth.find("$default"); // default method registered ? |
if (it_match != fMapMeth.end()) { |
return (it_match->second)(args); |
} |
Tcl_WrongNumArgs(interp, 1, args.Objv(), "option ?args?"); // or fail |
return kERR; |
} |
|
// here if at least method name given |
string name(Tcl_GetString(args[1])); |
|
it_match = fMapMeth.lower_bound(name); |
|
// no leading substring match |
if (it_match==fMapMeth.end() || |
name!=it_match->first.substr(0,name.length())) { |
|
mmap_cit_t it_un = fMapMeth.find("$unknown"); // unknown method registered ? |
if (it_un!=fMapMeth.end()) { |
return (it_un->second)(args); |
} |
|
Tcl_AppendResult(interp, "-E: bad option '", name.c_str(), |
"': must be ", NULL); |
const char* delim = ""; |
for (mmap_cit_t it1=fMapMeth.begin(); it1!=fMapMeth.end(); it1++) { |
if (it1->first.c_str()[0] != '$') { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
} |
return kERR; |
} |
|
// check for ambiguous substring match |
if (name != it_match->first) { |
mmap_cit_t it1 = it_match; |
it1++; |
if (it1!=fMapMeth.end() && name==it1->first.substr(0,name.length())) { |
Tcl_AppendResult(interp, "-E: ambiguous option '", |
name.c_str(), "': must be ", NULL); |
const char* delim = ""; |
for (it1=it_match; it1!=fMapMeth.end() && |
name==it1->first.substr(0,name.length()); it1++) { |
Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL); |
delim = ","; |
} |
return kERR; |
} |
} |
|
return (it_match->second)(args); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclCmdBase::AddMeth(const std::string& name, const methfo_t& methfo) |
{ |
mmap_ins_t ret = fMapMeth.insert(mmap_val_t(name, methfo)); |
if (ret.second == false) // or use !(ret.second) |
throw Rexception("RtclCmdBase::AddMeth:", |
string("Bad args: duplicate name: '") + name + "'"); |
return; |
} |
|
} // end namespace Retro |
/RtclCmdBase.hpp
0,0 → 1,70
// $Id: RtclCmdBase.hpp 511 2013-04-27 13:51:46Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-04-26 511 1.0.1 AddMeth() now public |
// 2013-02-02 480 1.0 Initial version (refactored out from ProxyBase) |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclCmdBase.hpp 511 2013-04-27 13:51:46Z mueller $ |
\brief Declaration of class RtclCmdBase. |
*/ |
|
#ifndef included_Retro_RtclCmdBase |
#define included_Retro_RtclCmdBase 1 |
|
#include "tcl.h" |
|
#include <string> |
#include <map> |
|
#include "boost/utility.hpp" |
#include "boost/function.hpp" |
|
#include "RtclArgs.hpp" |
|
namespace Retro { |
|
class RtclCmdBase : private boost::noncopyable { |
public: |
typedef boost::function<int(RtclArgs&)> methfo_t; |
|
typedef std::map<std::string, methfo_t> mmap_t; |
typedef mmap_t::iterator mmap_it_t; |
typedef mmap_t::const_iterator mmap_cit_t; |
typedef mmap_t::value_type mmap_val_t; |
|
RtclCmdBase(); |
virtual ~RtclCmdBase(); |
|
int DispatchCmd(RtclArgs& args); |
void AddMeth(const std::string& name, const methfo_t& methfo); |
|
// some constants (also defined in cpp) |
static const int kOK = TCL_OK; //<! |
static const int kERR = TCL_ERROR; //<! |
|
protected: |
|
protected: |
mmap_t fMapMeth; //!< map for named methods |
}; |
|
} // end namespace Retro |
|
//#include "RtclCmdBase.ipp" |
|
#endif |
/RtclProxyBase.cpp
0,0 → 1,160
// $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-09 485 1.4.2 add CommandName() |
// 2013-02-05 483 1.4.1 ClassCmdConfig: use RtclArgs |
// 2013-02-02 480 1.4 factor out RtclCmdBase base class |
// 2013-02-01 479 1.3 add DispatchCmd(), support $unknown method |
// 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-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclProxyBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation of RtclProxyBase. |
*/ |
|
#include "RtclProxyBase.hpp" |
|
#include "RtclContext.hpp" |
#include "Rtcl.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclProxyBase |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
typedef std::pair<RtclProxyBase::mmap_it_t, bool> mmap_ins_t; |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclProxyBase::RtclProxyBase(const std::string& type) |
: RtclCmdBase(), |
fType(type), |
fInterp(0) |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclProxyBase::RtclProxyBase(const std::string& type, Tcl_Interp* interp, |
const char* name) |
: RtclCmdBase(), |
fType(type), |
fInterp(0) |
{ |
CreateObjectCmd(interp, name); |
} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclProxyBase::~RtclProxyBase() |
{ |
if (fInterp) RtclContext::Find(fInterp).UnRegisterProxy(this); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclProxyBase::ClassCmdConfig(RtclArgs& args) |
{ |
if (!args.AllDone()) return kERR; |
return kOK; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
std::string RtclProxyBase::CommandName() const |
{ |
return string(Tcl_GetCommandName(fInterp, fCmdToken)); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclProxyBase::CreateObjectCmd(Tcl_Interp* interp, const char* name) |
{ |
fInterp = interp; |
fCmdToken = |
Tcl_CreateObjCommand(interp, name, ThunkTclObjectCmd, (ClientData) this, |
(Tcl_CmdDeleteProc *) ThunkTclCmdDeleteProc); |
RtclContext::Find(interp).RegisterProxy(this); |
Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) this); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclProxyBase::TclObjectCmd(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]) |
{ |
RtclArgs args(interp, objc, objv, 2); |
return DispatchCmd(args); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclProxyBase::ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp, |
int objc, Tcl_Obj* const objv[]) |
{ |
if (!cdata) { |
Tcl_AppendResult(interp, "-E: BUG! ThunkTclObjectCmd called with cdata==0", |
NULL); |
return TCL_ERROR; |
} |
|
try { |
return ((RtclProxyBase*) cdata)->TclObjectCmd(interp, objc, objv); |
} catch (exception& e) { |
Rtcl::AppendResultNewLines(interp); |
Tcl_AppendResult(interp, "-E: exception caught '", e.what(), "'", NULL); |
} |
return TCL_ERROR; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclProxyBase::ThunkTclCmdDeleteProc(ClientData cdata) |
{ |
Tcl_DeleteExitHandler((Tcl_ExitProc*) ThunkTclExitProc, cdata); |
delete ((RtclProxyBase*) cdata); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclProxyBase::ThunkTclExitProc(ClientData cdata) |
{ |
delete ((RtclProxyBase*) cdata); |
return; |
} |
|
} // end namespace Retro |
/RtclGetList.hpp
0,0 → 1,71
// $Id: RtclGetList.hpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGetList.hpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Declaration of class \c RtclGetList. |
*/ |
|
#ifndef included_Retro_RtclGetList |
#define included_Retro_RtclGetList 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
#include <map> |
|
#include "boost/utility.hpp" |
#include "boost/function.hpp" |
|
#include "RtclGet.hpp" |
#include "librtcltools/RtclArgs.hpp" |
|
namespace Retro { |
|
class RtclGetList : private boost::noncopyable { |
public: |
RtclGetList(); |
virtual ~RtclGetList(); |
|
void Add(const std::string& name, RtclGetBase* pget); |
|
template <class TP> |
void Add(const std::string& name, |
const boost::function<TP()>& get); |
|
int M_get(RtclArgs& args); |
|
protected: |
|
|
protected: |
typedef std::map<std::string, RtclGetBase*> map_t; |
typedef map_t::iterator map_it_t; |
typedef map_t::const_iterator map_cit_t; |
typedef map_t::value_type map_val_t; |
|
map_t fMap; |
}; |
|
} // end namespace Retro |
|
#include "RtclGetList.ipp" |
|
#endif |
/RtclProxyBase.hpp
0,0 → 1,84
// $Id: RtclProxyBase.hpp 486 2013-02-10 22:34:43Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-09 485 1.4.2 add CommandName() |
// 2013-02-05 483 1.4.1 ClassCmdConfig: use RtclArgs |
// 2013-02-02 480 1.4 factor out RtclCmdBase base class |
// 2013-02-01 479 1.3 add DispatchCmd(), support $unknown method |
// 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 |
// use boost::noncopyable (instead of private dcl's) |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclProxyBase.hpp 486 2013-02-10 22:34:43Z mueller $ |
\brief Declaration of class RtclProxyBase. |
*/ |
|
#ifndef included_Retro_RtclProxyBase |
#define included_Retro_RtclProxyBase 1 |
|
#include "tcl.h" |
|
#include <string> |
#include <map> |
|
#include "RtclCmdBase.hpp" |
|
#include "RtclArgs.hpp" |
|
namespace Retro { |
|
class RtclProxyBase : public RtclCmdBase { |
public: |
|
explicit RtclProxyBase(const std::string& type = std::string()); |
RtclProxyBase(const std::string& type, Tcl_Interp* interp, |
const char* name); |
virtual ~RtclProxyBase(); |
|
virtual int ClassCmdConfig(RtclArgs& args); |
|
const std::string& Type() const; |
Tcl_Command Token() const; |
std::string CommandName() const; |
|
protected: |
void SetType(const std::string& type); |
|
void CreateObjectCmd(Tcl_Interp* interp, const char* name); |
|
int TclObjectCmd(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]); |
|
static int ThunkTclObjectCmd(ClientData cdata, Tcl_Interp* interp, |
int objc, Tcl_Obj* const objv[]); |
static void ThunkTclCmdDeleteProc(ClientData cdata); |
static void ThunkTclExitProc(ClientData cdata); |
|
protected: |
std::string fType; //!< proxied type name |
Tcl_Interp* fInterp; //!< tcl interpreter |
Tcl_Command fCmdToken; //!< cmd token for object command |
}; |
|
} // end namespace Retro |
|
#include "RtclProxyBase.ipp" |
|
#endif |
/RtclGetList.ipp
0,0 → 1,39
// $Id: RtclGetList.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGetList.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of class RtclGetList. |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline void RtclGetList::Add(const std::string& name, |
const boost::function<TP()>& get) |
{ |
Add(name, new RtclGet<TP>(get)); |
return; |
} |
|
} // end namespace Retro |
/RtclProxyBase.ipp
0,0 → 1,55
// $Id: RtclProxyBase.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// 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 |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-08 484 1.0.1 add CommandName() |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-13 361 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclProxyBase.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of RtclProxyBase. |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline const std::string& RtclProxyBase::Type() const |
{ |
return fType; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Command RtclProxyBase::Token() const |
{ |
return fCmdToken; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclProxyBase::SetType(const std::string& type) |
{ |
fType = type; |
return; |
} |
|
} // end namespace Retro |
/RtclProxyOwned.hpp
0,0 → 1,58
// $Id: RtclProxyOwned.hpp 490 2013-02-22 18:43:26Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-05 482 1.1 use shared_ptr to TO*; add ObjPtr(); |
// 2011-02-13 361 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclProxyOwned.hpp 490 2013-02-22 18:43:26Z mueller $ |
\brief Declaration of class RtclProxyOwned. |
*/ |
|
#ifndef included_Retro_RtclProxyOwned |
#define included_Retro_RtclProxyOwned 1 |
|
#include "boost/shared_ptr.hpp" |
|
#include "RtclProxyBase.hpp" |
|
namespace Retro { |
|
template <class TO> |
class RtclProxyOwned : public RtclProxyBase { |
public: |
RtclProxyOwned(); |
RtclProxyOwned(const std::string& type); |
RtclProxyOwned(const std::string& type, Tcl_Interp* interp, |
const char* name, TO* pobj=0); |
~RtclProxyOwned(); |
|
TO& Obj(); |
const boost::shared_ptr<TO>& ObjSPtr(); |
|
protected: |
boost::shared_ptr<TO> fspObj; //!< sptr to managed object |
|
}; |
|
} // end namespace Retro |
|
// implementation is all inline |
#include "RtclProxyOwned.ipp" |
|
#endif |
/RtclProxyOwned.ipp
0,0 → 1,91
// $Id: RtclProxyOwned.ipp 491 2013-02-23 12:41:18Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-05 482 1.1 use shared_ptr to TO*; add ObjPtr(); |
// 2011-02-13 361 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: |
\brief Implemenation (all inline) of class RtclProxyOwned. |
*/ |
|
/*! |
\class Retro::RtclProxyOwned |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
template <class TO> |
inline RtclProxyOwned<TO>::RtclProxyOwned() |
: RtclProxyBase(), |
fspObj() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TO> |
inline RtclProxyOwned<TO>::RtclProxyOwned(const std::string& type) |
: RtclProxyBase(type), |
fspObj() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TO> |
inline RtclProxyOwned<TO>::RtclProxyOwned(const std::string& type, |
Tcl_Interp* interp, const char* name, |
TO* pobj) |
: RtclProxyBase(type), |
fspObj(pobj) |
{ |
CreateObjectCmd(interp, name); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TO> |
inline RtclProxyOwned<TO>::~RtclProxyOwned() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TO> |
inline TO& RtclProxyOwned<TO>::Obj() |
{ |
return *fspObj; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TO> |
inline const boost::shared_ptr<TO>& RtclProxyOwned<TO>::ObjSPtr() |
{ |
return fspObj; |
} |
|
} // end namespace Retro |
/RtclContext.cpp
0,0 → 1,193
// $Id: RtclContext.cpp 492 2013-02-24 22:14:47Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-03 481 1.0.3 use Rexception |
// 2013-01-12 474 1.0.2 add FindProxy() method |
// 2011-03-12 368 1.0.1 drop fExitSeen, get exit handling right |
// 2011-02-18 362 1.0 Initial version |
// 2011-02-13 361 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclContext.cpp 492 2013-02-24 22:14:47Z mueller $ |
\brief Implemenation of RtclContext. |
*/ |
|
#include <iostream> |
|
#include "RtclContext.hpp" |
|
#include "librtools/Rexception.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclContext |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
typedef std::pair<RtclContext::cset_it_t, bool> cset_ins_t; |
typedef std::pair<RtclContext::pset_it_t, bool> pset_ins_t; |
|
RtclContext::xmap_t RtclContext::fMapContext; |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
RtclContext::RtclContext(Tcl_Interp* interp) |
: fInterp(interp), |
fSetClass(), |
fSetProxy() |
{} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclContext::~RtclContext() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclContext::RegisterClass(RtclClassBase* pobj) |
{ |
cset_ins_t ret = fSetClass.insert(pobj); |
if (ret.second == false) // or use !(ret.second) |
throw Rexception("RtclContext::RegisterClass()", |
"Bad args: duplicate pointer"); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclContext::UnRegisterClass(RtclClassBase* pobj) |
{ |
fSetClass.erase(pobj); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclContext::RegisterProxy(RtclProxyBase* pobj) |
{ |
pset_ins_t ret = fSetProxy.insert(pobj); |
if (ret.second == false) // or use !(ret.second) |
throw Rexception("RtclContext::RegisterProxy()", |
"Bad args: duplicate pointer"); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclContext::UnRegisterProxy(RtclProxyBase* pobj) |
{ |
fSetProxy.erase(pobj); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclContext::CheckProxy(RtclProxyBase* pobj) |
{ |
pset_it_t it = fSetProxy.find(pobj); |
return it != fSetProxy.end(); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclContext::CheckProxy(RtclProxyBase* pobj, const string& type) |
{ |
pset_it_t it = fSetProxy.find(pobj); |
if (it == fSetProxy.end()) return false; |
return (*it)->Type() == type; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclContext::ListProxy(std::vector<RtclProxyBase*>& list, |
const std::string& type) |
{ |
list.clear(); |
for (pset_it_t it = fSetProxy.begin(); it != fSetProxy.end(); it++) { |
if (type.length() == 0 || (*it)->Type()==type) { |
list.push_back(*it); |
} |
} |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclProxyBase* RtclContext::FindProxy(const std::string& type, |
const std::string& name) |
{ |
for (pset_it_t it = fSetProxy.begin(); it != fSetProxy.end(); it++) { |
if (type.length() == 0 || (*it)->Type()==type) { |
const char* cmdname = Tcl_GetCommandName(fInterp, (*it)->Token()); |
if (name == cmdname) return *it; |
} |
} |
return 0; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclContext& RtclContext::Find(Tcl_Interp* interp) |
{ |
RtclContext* pcntx = 0; |
xmap_it_t it = fMapContext.find(interp); |
if (it != fMapContext.end()) { |
pcntx = it->second; |
} else { |
pcntx = new RtclContext(interp); |
fMapContext.insert(xmap_val_t(interp, pcntx)); |
Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) pcntx); |
|
} |
return *pcntx; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
// Note: tcl exit handlers are executed in inverse order of creation. |
// If Find() is called before any Class or Proxy cleanup handlers |
// are created the exit handler created in Find() will be called |
// last, when all map entries have been erased. |
|
void RtclContext::ThunkTclExitProc(ClientData cdata) |
{ |
RtclContext* pcntx = (RtclContext*) cdata; |
if (pcntx->fSetClass.empty() && pcntx->fSetProxy.empty()) { |
delete pcntx; |
} else { |
cerr << "RtclContext::ThunkTclExitProc called when maps non-empty" << endl; |
} |
return; |
} |
|
} // end namespace Retro |
/RtclGet.hpp
0,0 → 1,56
// $Id: RtclGet.hpp 487 2013-02-12 19:14:38Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGet.hpp 487 2013-02-12 19:14:38Z mueller $ |
\brief Declaration of class \c RtclGet. |
*/ |
|
#ifndef included_Retro_RtclGet |
#define included_Retro_RtclGet 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
|
#include "boost/function.hpp" |
|
#include "RtclGetBase.hpp" |
|
namespace Retro { |
|
template <class TP> |
class RtclGet : public RtclGetBase { |
public: |
explicit RtclGet(const boost::function<TP()>& get); |
~RtclGet(); |
|
virtual Tcl_Obj* operator()() const; |
|
protected: |
boost::function<TP()> fGet; |
}; |
|
|
} // end namespace Retro |
|
#include "RtclGet.ipp" |
|
#endif |
/RtclGet.ipp
0,0 → 1,189
// $Id: RtclGet.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGet.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of class RtclGet. |
*/ |
|
/*! |
\class Retro::RtclGet |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline RtclGet<TP>::RtclGet(const boost::function<TP()>& get) |
: fGet(get) |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline RtclGet<TP>::~RtclGet() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<bool>::operator()() const |
{ |
bool val = fGet(); |
return Tcl_NewBooleanObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<char>::operator()() const |
{ |
char val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<signed char>::operator()() const |
{ |
signed char val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<unsigned char>::operator()() const |
{ |
unsigned char val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<short>::operator()() const |
{ |
short val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<unsigned short>::operator()() const |
{ |
unsigned short val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<int>::operator()() const |
{ |
int val = fGet(); |
return Tcl_NewIntObj(val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<unsigned int>::operator()() const |
{ |
unsigned int val = fGet(); |
return Tcl_NewIntObj((int)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<long>::operator()() const |
{ |
long val = fGet(); |
return Tcl_NewLongObj(val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<unsigned long>::operator()() const |
{ |
unsigned long val = fGet(); |
return Tcl_NewLongObj((long)val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<float>::operator()() const |
{ |
float val = fGet(); |
return Tcl_NewDoubleObj(val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<double>::operator()() const |
{ |
double val = fGet(); |
return Tcl_NewDoubleObj(val); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<std::string>::operator()() const |
{ |
std::string val = fGet(); |
return Tcl_NewStringObj((char*) val.data(), val.length()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline Tcl_Obj* RtclGet<const std::string&>::operator()() const |
{ |
std::string val = fGet(); |
return Tcl_NewStringObj((char*) val.data(), val.length()); |
} |
|
} // end namespace Retro |
|
/RtclContext.hpp
0,0 → 1,88
// $Id: RtclContext.hpp 490 2013-02-22 18:43:26Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-01-12 474 1.0.3 add FindProxy() method |
// 2011-04-24 380 1.0.2 use boost::noncopyable (instead of private dcl's) |
// 2011-03-12 368 1.0.1 drop fExitSeen, get exit handling right |
// 2011-02-18 362 1.0 Initial version |
// 2011-02-18 362 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclContext.hpp 490 2013-02-22 18:43:26Z mueller $ |
\brief Declaration of class RtclContext. |
*/ |
|
#ifndef included_Retro_RtclContext |
#define included_Retro_RtclContext 1 |
|
#include "tcl.h" |
|
#include <string> |
#include <set> |
#include <map> |
|
#include "boost/utility.hpp" |
|
#include "RtclClassBase.hpp" |
#include "RtclProxyBase.hpp" |
|
namespace Retro { |
|
class RtclContext : private boost::noncopyable { |
public: |
typedef std::set<RtclClassBase*> cset_t; |
typedef cset_t::iterator cset_it_t; |
typedef std::set<RtclProxyBase*> pset_t; |
typedef pset_t::iterator pset_it_t; |
typedef std::map<Tcl_Interp*, RtclContext*> xmap_t; |
typedef xmap_t::iterator xmap_it_t; |
typedef xmap_t::value_type xmap_val_t; |
|
explicit RtclContext(Tcl_Interp* interp); |
virtual ~RtclContext(); |
|
void RegisterClass(RtclClassBase* pobj); |
void UnRegisterClass(RtclClassBase* pobj); |
|
void RegisterProxy(RtclProxyBase* pobj); |
void UnRegisterProxy(RtclProxyBase* pobj); |
bool CheckProxy(RtclProxyBase* pobj); |
bool CheckProxy(RtclProxyBase* pobj, const std::string& type); |
|
void ListProxy(std::vector<RtclProxyBase*>& list, |
const std::string& type); |
RtclProxyBase* FindProxy(const std::string& type, |
const std::string& name); |
|
static RtclContext& Find(Tcl_Interp* interp); |
|
static void ThunkTclExitProc(ClientData cdata); |
|
protected: |
|
Tcl_Interp* fInterp; //!< associated tcl interpreter |
cset_t fSetClass; //!< set for Class objects |
pset_t fSetProxy; //!< set for Proxy objects |
|
static xmap_t fMapContext; //!< map of contexts |
}; |
|
} // end namespace Retro |
|
//#include "RtclContext.ipp" |
|
#endif |
/RtclOPtr.ipp
0,0 → 1,102
// $Id: RtclOPtr.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// 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 |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2011-02-20 363 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclOPtr.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of RtclOPtr. |
*/ |
|
/*! |
\class Retro::RtclOPtr |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
inline RtclOPtr::RtclOPtr() |
: fpObj(0) |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline RtclOPtr::RtclOPtr(Tcl_Obj* pobj) |
: fpObj(pobj) |
{ |
if (fpObj) Tcl_IncrRefCount(fpObj); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline RtclOPtr::RtclOPtr(const RtclOPtr& rhs) |
: fpObj(rhs.fpObj) |
{ |
if (fpObj) Tcl_IncrRefCount(fpObj); |
} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
inline RtclOPtr::~RtclOPtr() |
{ |
if (fpObj) Tcl_DecrRefCount(fpObj); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline RtclOPtr::operator Tcl_Obj*() const |
{ |
return fpObj; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline bool RtclOPtr::operator !() const |
{ |
return fpObj==0; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline RtclOPtr& RtclOPtr::operator=(const RtclOPtr& rhs) |
{ |
if (&rhs == this) return *this; |
return operator=(rhs.fpObj); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline RtclOPtr& RtclOPtr::operator=(Tcl_Obj* pobj) |
{ |
if (fpObj) Tcl_DecrRefCount(fpObj); |
fpObj = pobj; |
if (fpObj) Tcl_IncrRefCount(fpObj); |
return *this; |
} |
|
} // end namespace Retro |
/RtclSetList.hpp
0,0 → 1,71
// $Id: RtclSetList.hpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSetList.hpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Declaration of class \c RtclSetList. |
*/ |
|
#ifndef included_Retro_RtclSetList |
#define included_Retro_RtclSetList 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
#include <map> |
|
#include "boost/utility.hpp" |
#include "boost/function.hpp" |
|
#include "RtclSet.hpp" |
#include "librtcltools/RtclArgs.hpp" |
|
namespace Retro { |
|
class RtclSetList : private boost::noncopyable { |
public: |
RtclSetList(); |
virtual ~RtclSetList(); |
|
void Add(const std::string& name, RtclSetBase* pset); |
|
template <class TP> |
void Add(const std::string& name, |
const boost::function<void(TP)>& set); |
|
int M_set(RtclArgs& args); |
|
protected: |
|
|
protected: |
typedef std::map<std::string, RtclSetBase*> map_t; |
typedef map_t::iterator map_it_t; |
typedef map_t::const_iterator map_cit_t; |
typedef map_t::value_type map_val_t; |
|
map_t fMap; |
}; |
|
} // end namespace Retro |
|
#include "RtclSetList.ipp" |
|
#endif |
/RtclSetList.ipp
0,0 → 1,39
// $Id: RtclSetList.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSetList.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of class RtclSetList. |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline void RtclSetList::Add(const std::string& name, |
const boost::function<void(TP)>& set) |
{ |
Add(name, new RtclSet<TP>(set)); |
return; |
} |
|
} // end namespace Retro |
/RtclStats.cpp
0,0 → 1,155
// $Id: RtclStats.cpp 495 2013-03-06 17:13:48Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-03-06 495 1.0.1 Rename Exec->Collect |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-20 363 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclStats.cpp 495 2013-03-06 17:13:48Z mueller $ |
\brief Implemenation of RtclStats. |
*/ |
|
#include <sstream> |
|
#include "RtclStats.hpp" |
#include "RtclNameSet.hpp" |
#include "RtclOPtr.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclStats |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclStats::GetArgs(RtclArgs& args, Context& cntx) |
{ |
static RtclNameSet optset("-lname|-ltext|-lvalue|-lpair|-lall|" |
"-atext|-avalue|-print"); |
|
string opt; |
string varname; |
string format; |
int width=0; |
int prec=0; |
|
if (args.NextOpt(opt, optset)) { |
if (opt == "-atext" || opt == "-avalue") { |
if (!args.GetArg("varName", varname)) return false; |
} else if (opt == "-print") { |
if (!args.GetArg("?format", format)) return false; |
if (!args.GetArg("?width", width, 0, 32)) return false; |
if (!args.GetArg("?prec", prec, 0, 32)) return false; |
} |
|
} else { |
opt = "-print"; |
width = 12; |
} |
if (!args.AllDone()) return false; |
|
cntx.opt = opt; |
cntx.varname = varname; |
cntx.format = format; |
cntx.width = width; |
cntx.prec = prec; |
|
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool RtclStats::Collect(RtclArgs& args, const Context& cntx, |
const Rstats& stats) |
{ |
Tcl_Interp* interp = args.Interp(); |
Tcl_Obj* plist = Tcl_GetObjResult(interp); |
|
if (cntx.opt == "-lname") { // -lname ------------------------- |
for (size_t i=0; i<stats.Size(); i++) { |
const string& name(stats.Name(i)); |
RtclOPtr pobj(Tcl_NewStringObj(name.data(), name.length())); |
if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false; |
} |
|
} else if (cntx.opt == "-ltext") { // -ltext ------------------------- |
for (size_t i=0; i<stats.Size(); i++) { |
const string& text(stats.Text(i)); |
RtclOPtr pobj(Tcl_NewStringObj(text.data(), text.length())); |
if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false; |
} |
|
} else if (cntx.opt == "-lvalue") { |
for (size_t i=0; i<stats.Size(); i++) { // -lvalue ------------------------ |
RtclOPtr pobj(Tcl_NewDoubleObj(stats.Value(i))); |
if (Tcl_ListObjAppendElement(interp, plist, pobj) != TCL_OK) return false; |
} |
|
} else if (cntx.opt == "-lpair" || cntx.opt == "-lall") { // -lpair -lall --- |
for (size_t i=0; i<stats.Size(); i++) { |
const string& name(stats.Name(i)); |
RtclOPtr ptup(Tcl_NewListObj(0,0)); |
Tcl_ListObjAppendElement(NULL, ptup, |
Tcl_NewDoubleObj(stats.Value(i))); |
Tcl_ListObjAppendElement(NULL, ptup, |
Tcl_NewStringObj(name.data(), name.length())); |
if (cntx.opt == "-lall") { |
const string& text(stats.Text(i)); |
Tcl_ListObjAppendElement(NULL, ptup, |
Tcl_NewStringObj(text.data(), text.length())); |
} |
if (Tcl_ListObjAppendElement(interp, plist, ptup) != TCL_OK) return false; |
} |
|
} else if (cntx.opt == "-atext") { // -atext ------------------------- |
for (size_t i=0; i<stats.Size(); i++) { |
const string& text(stats.Text(i)); |
RtclOPtr pobj(Tcl_NewStringObj(text.data(), text.length())); |
if (!Tcl_SetVar2Ex(interp, cntx.varname.c_str(), stats.Name(i).c_str(), |
pobj, TCL_LEAVE_ERR_MSG)) return false; |
} |
|
} else if (cntx.opt == "-avalue") { // -avalue ------------------------ |
for (size_t i=0; i<stats.Size(); i++) { |
RtclOPtr pobj(Tcl_NewDoubleObj(stats.Value(i))); |
if (!Tcl_SetVar2Ex(interp, cntx.varname.c_str(), stats.Name(i).c_str(), |
pobj, TCL_LEAVE_ERR_MSG)) return false; |
} |
|
} else if (cntx.opt == "-print") { // -print ------------------------- |
ostringstream sos; |
stats.Print(sos, cntx.format.c_str(), cntx.width, cntx.prec); |
args.AppendResultLines(sos); |
|
} else { |
args.AppendResult("-E: BUG! RtclStats::Collect: bad option '", |
cntx.opt.c_str(), "'", NULL); |
return false; |
} |
|
return true; |
} |
|
} // end namespace Retro |
/RtclSet.hpp
0,0 → 1,57
// $Id: RtclSet.hpp 487 2013-02-12 19:14:38Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSet.hpp 487 2013-02-12 19:14:38Z mueller $ |
\brief Declaration of class \c RtclSet. |
*/ |
|
#ifndef included_Retro_RtclSet |
#define included_Retro_RtclSet 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
|
#include "boost/function.hpp" |
|
#include "librtools/Rexception.hpp" |
#include "RtclSetBase.hpp" |
|
namespace Retro { |
|
template <class TP> |
class RtclSet : public RtclSetBase { |
public: |
explicit RtclSet(const boost::function<void(TP)>& set); |
~RtclSet(); |
|
virtual void operator()(RtclArgs& args) const; |
|
protected: |
boost::function<void(TP)> fSet; |
}; |
|
|
} // end namespace Retro |
|
#include "RtclSet.ipp" |
|
#endif |
/RtclSet.ipp
0,0 → 1,250
// $Id: RtclSet.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSet.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of class RtclSet. |
*/ |
|
/*! |
\class Retro::RtclSet |
\brief FIXME_docs |
*/ |
|
#include <climits> |
#include <cfloat> |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline RtclSet<TP>::RtclSet(const boost::function<void(TP)>& set) |
: fSet(set) |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline RtclSet<TP>::~RtclSet() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<bool>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetBooleanFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet((bool)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<char>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if (val < CHAR_MIN || val > CHAR_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'char'"); |
|
fSet((char)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<signed char>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if (val < SCHAR_MIN || val > SCHAR_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'signed char'"); |
|
fSet((signed char)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<unsigned char>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if ((unsigned int)val > UCHAR_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'unsigned char'"); |
|
fSet((unsigned char)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<short>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if (val < SHRT_MIN || val > SHRT_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'short'"); |
|
fSet((short)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<unsigned short>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if ((unsigned int)val > USHRT_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'unsigned short'"); |
|
fSet((unsigned short)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<int>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet(val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<unsigned int>::operator()(RtclArgs& args) const |
{ |
int val; |
if(Tcl_GetIntFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet((unsigned int) val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<long>::operator()(RtclArgs& args) const |
{ |
long val; |
if(Tcl_GetLongFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet(val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<unsigned long>::operator()(RtclArgs& args) const |
{ |
long val; |
if(Tcl_GetLongFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet((unsigned long) val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<float>::operator()(RtclArgs& args) const |
{ |
double val; |
if(Tcl_GetDoubleFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
if (val < -FLT_MAX || val > FLT_MAX) |
throw Rexception("RtclSet<>::oper()", |
"out of range for type 'float'"); |
|
fSet((float)val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<double>::operator()(RtclArgs& args) const |
{ |
double val; |
if(Tcl_GetDoubleFromObj(args.Interp(), args.CurrentArg(), &val) != TCL_OK) |
throw Rexception("RtclSet<>::oper()", "conversion error"); |
|
fSet(val); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <> |
inline void RtclSet<const std::string&>::operator()(RtclArgs& args) const |
{ |
char* val = Tcl_GetString(args.CurrentArg()); |
fSet(std::string(val)); |
return; |
} |
|
|
} // end namespace Retro |
|
/RtclStats.hpp
0,0 → 1,61
// $Id: RtclStats.hpp 495 2013-03-06 17:13:48Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-03-06 495 1.0.1 Rename Exec->Collect |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-20 363 0.1 fFirst draft |
// --------------------------------------------------------------------------- |
|
|
/*! |
\file |
\version $Id: RtclStats.hpp 495 2013-03-06 17:13:48Z mueller $ |
\brief Declaration of class RtclStats. |
*/ |
|
#ifndef included_Retro_RtclStats |
#define included_Retro_RtclStats 1 |
|
#include <string> |
|
#include "RtclArgs.hpp" |
#include "librtools/Rstats.hpp" |
|
namespace Retro { |
|
class RtclStats { |
public: |
struct Context { |
std::string opt; |
std::string varname; |
std::string format; |
int width; |
int prec; |
|
Context() |
: opt(), varname(), format(), width(0), prec(0) |
{} |
}; |
|
static bool GetArgs(RtclArgs& args, Context& cntx); |
static bool Collect(RtclArgs& args, const Context& cntx, |
const Rstats& stats); |
}; |
|
} // end namespace Retro |
|
//#include "RtclStats.ipp" |
|
#endif |
/RtclGetBase.cpp
0,0 → 1,49
// $Id: RtclGetBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGetBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation of class RtclGetBase. |
*/ |
|
#include "RtclGetBase.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclGetBase |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclGetBase::RtclGetBase() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclGetBase::~RtclGetBase() |
{} |
|
} // end namespace Retro |
/Rtcl.cpp
0,0 → 1,166
// $Id: Rtcl.cpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-01-06 473 1.0.4 add NewListIntObj(const uint(8|16)_t, ...) |
// 2011-03-13 369 1.0.2 add NewListIntObj(vector<uint8_t>) |
// 2011-03-05 366 1.0.1 add AppendResultNewLines() |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-13 361 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: Rtcl.cpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation of Rtcl. |
*/ |
|
#include "Rtcl.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::Rtcl |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* Rtcl::NewLinesObj(const std::string& str) |
{ |
const char* data = str.data(); |
int size = str.length(); |
if (size>0 && data[size-1]=='\n') size -= 1; |
return Tcl_NewStringObj(data, size); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* Rtcl::NewListIntObj(const uint8_t* data, size_t size) |
{ |
if (size == 0) return Tcl_NewListObj(0, NULL); |
|
vector<Tcl_Obj*> vobj; |
vobj.reserve(size); |
|
for (size_t i=0; i<size; i++) { |
vobj.push_back(Tcl_NewIntObj((int)data[i])); |
} |
return Tcl_NewListObj(vobj.size(), vobj.data()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* Rtcl::NewListIntObj(const uint16_t* data, size_t size) |
{ |
if (size == 0) return Tcl_NewListObj(0, NULL); |
|
vector<Tcl_Obj*> vobj; |
vobj.reserve(size); |
|
for (size_t i=0; i<size; i++) { |
vobj.push_back(Tcl_NewIntObj((int)data[i])); |
} |
return Tcl_NewListObj(vobj.size(), vobj.data()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* Rtcl::NewListIntObj(const std::vector<uint8_t>& vec) |
{ |
return NewListIntObj(vec.data(), vec.size()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
Tcl_Obj* Rtcl::NewListIntObj(const std::vector<uint16_t>& vec) |
{ |
return NewListIntObj(vec.data(), vec.size()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool Rtcl::SetVar(Tcl_Interp* interp, const std::string& varname, Tcl_Obj* pobj) |
{ |
Tcl_Obj* pret = 0; |
|
size_t pos_pbeg = varname.find_first_of('('); |
size_t pos_pend = varname.find_first_of(')'); |
if (pos_pbeg != string::npos || pos_pend != string::npos) { |
if (pos_pbeg == string::npos || pos_pbeg == 0 || |
pos_pend == string::npos || pos_pend != varname.length()-1 || |
pos_pend-pos_pbeg <= 1) { |
Tcl_AppendResult(interp, "illformed array name '", varname.c_str(), |
"'", NULL); |
return false; |
} |
string arrname(varname.substr(0,pos_pbeg)); |
string elename(varname.substr(pos_pbeg+1, pos_pend-pos_pbeg-1)); |
|
pret = Tcl_SetVar2Ex(interp, arrname.c_str(), elename.c_str(), pobj, |
TCL_LEAVE_ERR_MSG); |
} else { |
pret = Tcl_SetVar2Ex(interp, varname.c_str(), NULL, pobj, |
TCL_LEAVE_ERR_MSG); |
} |
|
return pret!=0; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
bool Rtcl::SetVarOrResult(Tcl_Interp* interp, const std::string& varname, |
Tcl_Obj* pobj) |
{ |
if (varname != "-") { |
return SetVar(interp, varname, pobj); |
} |
Tcl_SetObjResult(interp, pobj); |
return true; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void Rtcl::AppendResultNewLines(Tcl_Interp* interp) |
{ |
// check whether ObjResult is non-empty, in that case add an '\n' |
// that allows to append output from multiple AppendResultLines properly |
const char* res = Tcl_GetStringResult(interp); |
if (res && res[0]) { |
Tcl_AppendResult(interp, "\n", NULL); |
} |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void Rtcl::SetResult(Tcl_Interp* interp, const std::string& str) |
{ |
Tcl_SetObjResult(interp, NewLinesObj(str)); |
return; |
} |
|
} // end namespace Retro |
/RtclGetBase.hpp
0,0 → 1,50
// $Id: RtclGetBase.hpp 487 2013-02-12 19:14:38Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclGetBase.hpp 487 2013-02-12 19:14:38Z mueller $ |
\brief Declaration of class \c RtclGetBase. |
*/ |
|
#ifndef included_Retro_RtclGetBase |
#define included_Retro_RtclGetBase 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
|
#include "boost/function.hpp" |
|
namespace Retro { |
|
class RtclGetBase { |
public: |
RtclGetBase(); |
virtual ~RtclGetBase(); |
|
virtual Tcl_Obj* operator()() const = 0; |
}; |
|
|
} // end namespace Retro |
|
//#include "RtclGetBase.ipp" |
|
#endif |
/Rtcl.hpp
0,0 → 1,66
// $Id: Rtcl.hpp 486 2013-02-10 22:34:43Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-01-06 473 1.0.4 add NewListIntObj(const uint(8|16)_t, ...) |
// 2011-03-13 369 1.0.3 add NewListIntObj(vector<uint8_t>) |
// 2011-03-12 368 1.0.2 use namespace Rtcl |
// 2011-03-05 366 1.0.1 add AppendResultNewLines() |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-18 362 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: Rtcl.hpp 486 2013-02-10 22:34:43Z mueller $ |
\brief Declaration of class Rtcl. |
*/ |
|
#ifndef included_Retro_Rtcl |
#define included_Retro_Rtcl 1 |
|
#include "tcl.h" |
|
#include <cstddef> |
#include <string> |
#include <sstream> |
#include <vector> |
|
namespace Retro { |
|
namespace Rtcl { |
Tcl_Obj* NewLinesObj(const std::string& str); |
Tcl_Obj* NewLinesObj(std::ostringstream& sos); |
|
Tcl_Obj* NewListIntObj(const uint8_t* data, size_t size); |
Tcl_Obj* NewListIntObj(const uint16_t* data, size_t size); |
Tcl_Obj* NewListIntObj(const std::vector<uint8_t>& vec); |
Tcl_Obj* NewListIntObj(const std::vector<uint16_t>& vec); |
|
bool SetVar(Tcl_Interp* interp, |
const std::string& varname, Tcl_Obj* pobj); |
bool SetVarOrResult(Tcl_Interp* interp, |
const std::string& varname, Tcl_Obj* pobj); |
|
void AppendResultNewLines(Tcl_Interp* interp); |
|
void SetResult(Tcl_Interp* interp, const std::string& str); |
void SetResult(Tcl_Interp* interp, std::ostringstream& sos); |
}; |
|
} // end namespace Retro |
|
#include "Rtcl.ipp" |
|
#endif |
/Rtcl.ipp
0,0 → 1,47
// $Id: Rtcl.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// 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 |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-18 362 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: Rtcl.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of Rtcl. |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Obj* Rtcl::NewLinesObj(std::ostringstream& sos) |
{ |
return NewLinesObj(sos.str()); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void Rtcl::SetResult(Tcl_Interp* interp, std::ostringstream& sos) |
{ |
SetResult(interp, sos.str()); |
return; |
} |
|
|
} // end namespace Retro |
/RtclSetBase.cpp
0,0 → 1,49
// $Id: RtclSetBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSetBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation of class RtclSetBase. |
*/ |
|
#include "RtclSetBase.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclSetBase |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclSetBase::RtclSetBase() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
RtclSetBase::~RtclSetBase() |
{} |
|
} // end namespace Retro |
/RtclSetBase.hpp
0,0 → 1,52
// $Id: RtclSetBase.hpp 487 2013-02-12 19:14:38Z mueller $ |
// |
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-12 487 1.0 Initial version |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclSetBase.hpp 487 2013-02-12 19:14:38Z mueller $ |
\brief Declaration of class \c RtclSetBase. |
*/ |
|
#ifndef included_Retro_RtclSetBase |
#define included_Retro_RtclSetBase 1 |
|
#include "tcl.h" |
|
#include <cstdint> |
#include <string> |
|
#include "boost/function.hpp" |
|
#include "RtclArgs.hpp" |
|
namespace Retro { |
|
class RtclSetBase { |
public: |
RtclSetBase(); |
virtual ~RtclSetBase(); |
|
virtual void operator()(RtclArgs& args) const = 0; |
}; |
|
|
} // end namespace Retro |
|
//#include "RtclSetBase.ipp" |
|
#endif |
/RtclClassBase.cpp
0,0 → 1,206
// $Id: RtclClassBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-02-10 485 1.0.3 add static const defs |
// 2013-01-13 474 1.0.2 TclClassCmd(): check for existing Rtclproxy names |
// 2011-03-05 366 1.0.1 use AppendResultNewLines() in exception catcher |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclClassBase.cpp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation of RtclClassBase. |
*/ |
|
#include <string.h> |
|
#include <stdexcept> |
|
#include "RtclClassBase.hpp" |
#include "RtclContext.hpp" |
#include "RtclOPtr.hpp" |
#include "Rtcl.hpp" |
|
using namespace std; |
|
/*! |
\class Retro::RtclClassBase |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
// constants definitions |
|
const int RtclClassBase::kOK; |
const int RtclClassBase::kERR; |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
RtclClassBase::RtclClassBase(const std::string& type) |
: fType(type), |
fInterp(0) |
{} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
RtclClassBase::~RtclClassBase() |
{ |
if (fInterp) RtclContext::Find(fInterp).UnRegisterClass(this); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclClassBase::CreateClassCmd(Tcl_Interp* interp, const char* name) |
{ |
fInterp = interp; |
fCmdToken = |
Tcl_CreateObjCommand(interp, name, ThunkTclClassCmd, (ClientData) this, |
(Tcl_CmdDeleteProc *) ThunkTclCmdDeleteProc); |
RtclContext::Find(interp).RegisterClass(this); |
Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) this); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclClassBase::TclClassCmd(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]) |
{ |
// no args -> lists existing proxies |
if (objc == 1) { |
return ClassCmdList(interp); |
} |
|
// 2nd arg -delete -> delete proxy |
const char* name = Tcl_GetString(objv[1]); |
if (objc == 3 && strcmp(Tcl_GetString(objv[2]), "-delete")==0) { |
return ClassCmdDelete(interp, name); |
} |
|
// check if proxy of given name already existing |
RtclProxyBase* pprox = RtclContext::Find(interp).FindProxy("",name); |
if (pprox) { |
Tcl_AppendResult(interp, "-E: command name '", name, |
"' exists already as RtclProxy of type '", |
pprox->Type().c_str(), "'", NULL); |
return kERR; |
|
} |
|
// finally create new proxy |
return ClassCmdCreate(interp, objc, objv); |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclClassBase::ClassCmdList(Tcl_Interp* interp) |
{ |
std::vector<RtclProxyBase*> list; |
RtclContext::Find(interp).ListProxy(list, Type()); |
RtclOPtr rlist(Tcl_NewListObj(0, NULL)); |
|
for (size_t i=0; i<list.size(); i++) { |
const char* cmdname = Tcl_GetCommandName(interp, list[i]->Token()); |
RtclOPtr rval(Tcl_NewStringObj(cmdname, -1)); |
if (Tcl_ListObjAppendElement(interp, rlist, rval) != kOK) return kERR; |
} |
|
Tcl_SetObjResult(interp, rlist); |
|
return kOK; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclClassBase::ClassCmdDelete(Tcl_Interp* interp, const char* name) |
{ |
Tcl_CmdInfo cinfo; |
if (Tcl_GetCommandInfo(interp, name, &cinfo) == 0) { |
Tcl_AppendResult(interp, "-E: unknown command name '", name, "'", NULL); |
return kERR; |
} |
|
RtclContext& cntx = RtclContext::Find(interp); |
if (!cntx.CheckProxy((RtclProxyBase*) cinfo.objClientData)) { |
Tcl_AppendResult(interp, "-E: command '", name, "' is not a RtclProxy", |
NULL); |
return kERR; |
} |
if (!cntx.CheckProxy((RtclProxyBase*) cinfo.objClientData, Type())) { |
Tcl_AppendResult(interp, "-E: command '", name, |
"' is not a RtclProxy of type '", |
Type().c_str(), "'", NULL); |
return kERR; |
} |
|
int irc = Tcl_DeleteCommand(interp, name); |
if (irc != kOK) Tcl_AppendResult(interp, "-E: failed to delete '", name, |
"'", NULL); |
return irc; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
int RtclClassBase::ThunkTclClassCmd(ClientData cdata, Tcl_Interp* interp, |
int objc, Tcl_Obj* const objv[]) |
{ |
if (!cdata) { |
Tcl_AppendResult(interp, "-E: BUG! ThunkTclClassCmd called with cdata == 0", |
NULL); |
return kERR; |
} |
|
try { |
return ((RtclClassBase*) cdata)->TclClassCmd(interp, objc, objv); |
} catch (exception& e) { |
Rtcl::AppendResultNewLines(interp); |
Tcl_AppendResult(interp, "-E: exception caught in ThunkTclClassCmd: '", |
e.what(), "'", NULL); |
} |
return kERR; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclClassBase::ThunkTclCmdDeleteProc(ClientData cdata) |
{ |
Tcl_DeleteExitHandler((Tcl_ExitProc*) ThunkTclExitProc, cdata); |
delete ((RtclClassBase*) cdata); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
void RtclClassBase::ThunkTclExitProc(ClientData cdata) |
{ |
delete ((RtclClassBase*) cdata); |
return; |
} |
|
} // end namespace Retro |
/RtclArgs.ipp
0,0 → 1,182
// $Id: RtclArgs.ipp 495 2013-03-06 17:13:48Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-03-05 495 1.0.8 add SetResult(bool) |
// 2013-03-02 494 1.0.7 add Quit() method |
// 2013-02-01 479 1.0.5 add Objv() method |
// 2011-03-26 373 1.0.2 add SetResult(string) |
// 2011-03-05 366 1.0.1 add NDone(), NOptMiss(), SetResult(); |
// 2011-02-26 364 1.0 Initial version |
// 2011-02-18 362 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclArgs.ipp 495 2013-03-06 17:13:48Z mueller $ |
\brief Implemenation (inline) of RtclArgs. |
*/ |
|
#include "Rtcl.hpp" |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Interp* RtclArgs::Interp() const |
{ |
return fpInterp; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline int RtclArgs::Objc() const |
{ |
return fObjc; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Obj* const * RtclArgs::Objv() const |
{ |
return fObjv; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline bool RtclArgs::OptValid() const |
{ |
return !fOptErr; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline size_t RtclArgs::NDone() const |
{ |
return fNDone; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline size_t RtclArgs::NOptMiss() const |
{ |
return fNOptMiss; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(const std::string& str) |
{ |
Rtcl::SetResult(fpInterp, str); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(std::ostringstream& sos) |
{ |
Rtcl::SetResult(fpInterp, sos); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(bool val) |
{ |
Tcl_SetObjResult(fpInterp, Tcl_NewBooleanObj(val)); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(int val) |
{ |
Tcl_SetObjResult(fpInterp, Tcl_NewIntObj(val)); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(double val) |
{ |
Tcl_SetObjResult(fpInterp, Tcl_NewDoubleObj(val)); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::SetResult(Tcl_Obj* pobj) |
{ |
Tcl_SetObjResult(fpInterp, pobj); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::AppendResult(const std::string& str) |
{ |
Tcl_AppendResult(fpInterp, str.c_str(), NULL); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::AppendResult(std::ostringstream& sos) |
{ |
AppendResult(sos.str()); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclArgs::AppendResultLines(std::ostringstream& sos) |
{ |
AppendResultLines(sos.str()); |
return; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline int RtclArgs::Quit(const std::string& str) |
{ |
Tcl_AppendResult(fpInterp, str.c_str(), NULL); |
return TCL_ERROR; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Obj* RtclArgs::operator[](size_t ind) const |
{ |
return fObjv[ind]; |
} |
|
} // end namespace Retro |
/RtclClassBase.hpp
0,0 → 1,78
// $Id: RtclClassBase.hpp 486 2013-02-10 22:34:43Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2011-04-24 380 1.0.1 use boost::noncopyable (instead of private dcl's) |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclClassBase.hpp 486 2013-02-10 22:34:43Z mueller $ |
\brief Declaration of class RtclClassBase. |
*/ |
|
#ifndef included_Retro_RtclClassBase |
#define included_Retro_RtclClassBase 1 |
|
#include "boost/utility.hpp" |
|
#include "tcl.h" |
|
namespace Retro { |
|
class RtclClassBase : private boost::noncopyable { |
public: |
|
explicit RtclClassBase(const std::string& type = std::string()); |
virtual ~RtclClassBase(); |
|
const std::string& Type() const; |
Tcl_Command Token() const; |
|
// some constants (also defined in cpp) |
static const int kOK = TCL_OK; //<! |
static const int kERR = TCL_ERROR; //<! |
|
protected: |
void SetType(const std::string& type); |
|
void CreateClassCmd(Tcl_Interp* interp, const char* name); |
|
virtual int TclClassCmd(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]); |
|
virtual int ClassCmdList(Tcl_Interp* interp); |
virtual int ClassCmdDelete(Tcl_Interp* interp, const char* name); |
virtual int ClassCmdCreate(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]) = 0; |
|
static int ThunkTclClassCmd(ClientData cdata, Tcl_Interp* interp, |
int objc, Tcl_Obj* const objv[]); |
|
static void ThunkTclCmdDeleteProc(ClientData cdata); |
static void ThunkTclExitProc(ClientData cdata); |
|
protected: |
std::string fType; //!< classed type name |
Tcl_Interp* fInterp; //!< tcl interpreter |
Tcl_Command fCmdToken; //!< cmd token for class command |
}; |
|
} // end namespace Retro |
|
#include "RtclClassBase.ipp" |
|
#endif |
/RtclClassBase.ipp
0,0 → 1,54
// $Id: RtclClassBase.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// 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 |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-18 362 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclClassBase.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of RtclClassBase. |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline const std::string& RtclClassBase::Type() const |
{ |
return fType; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline Tcl_Command RtclClassBase::Token() const |
{ |
return fCmdToken; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
inline void RtclClassBase::SetType(const std::string& type) |
{ |
fType = type; |
return; |
} |
|
} // end namespace Retro |
/RtclClassOwned.hpp
0,0 → 1,56
// $Id: RtclClassOwned.hpp 482 2013-02-05 15:53:09Z mueller $ |
// |
// 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 |
// the terms of the GNU General Public License as published by the Free |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclClassOwned.hpp 482 2013-02-05 15:53:09Z mueller $ |
\brief Declaration of class RtclClassOwned. |
*/ |
|
#ifndef included_Retro_RtclClassOwned |
#define included_Retro_RtclClassOwned 1 |
|
#include "tcl.h" |
|
#include <string> |
|
#include "RtclClassBase.hpp" |
|
namespace Retro { |
|
template <class TP> |
class RtclClassOwned : public RtclClassBase { |
public: |
|
explicit RtclClassOwned(const std::string& type = std::string()); |
~RtclClassOwned(); |
|
int ClassCmdCreate(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]); |
|
static void CreateClass(Tcl_Interp* interp, const char* name, |
const std::string& type); |
}; |
|
} // end namespace Retro |
|
// implementation all inline |
#include "RtclClassOwned.ipp" |
|
#endif |
/RtclClassOwned.ipp
0,0 → 1,91
// $Id: RtclClassOwned.ipp 488 2013-02-16 18:49:47Z mueller $ |
// |
// Copyright 2011-2013 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de> |
// |
// 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 |
// Software Foundation, either version 2, or at your option any later version. |
// |
// This program is distributed in the hope that it will be useful, but |
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY |
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for complete details. |
// |
// Revision History: |
// Date Rev Version Comment |
// 2013-01-13 474 1.0.1 ClassCmdCreate(): fix configuration failed logic |
// 2011-02-20 363 1.0 Initial version |
// 2011-02-11 360 0.1 First draft |
// --------------------------------------------------------------------------- |
|
/*! |
\file |
\version $Id: RtclClassOwned.ipp 488 2013-02-16 18:49:47Z mueller $ |
\brief Implemenation (inline) of class RtclClassOwned. |
*/ |
|
#include <iostream> |
#include <string> |
|
#include "RtclProxyBase.hpp" |
#include "RtclArgs.hpp" |
|
/*! |
\class Retro::RtclClassOwned |
\brief FIXME_docs |
*/ |
|
// all method definitions in namespace Retro |
namespace Retro { |
|
//------------------------------------------+----------------------------------- |
//! Default constructor |
|
template <class TP> |
inline RtclClassOwned<TP>::RtclClassOwned(const std::string& type) |
: RtclClassBase(type) |
{} |
|
//------------------------------------------+----------------------------------- |
//! Destructor |
|
template <class TP> |
inline RtclClassOwned<TP>::~RtclClassOwned() |
{} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline int RtclClassOwned<TP>::ClassCmdCreate(Tcl_Interp* interp, int objc, |
Tcl_Obj* const objv[]) |
{ |
RtclArgs args(interp, objc, objv, 1); |
std::string name; |
if (!args.GetArg("name", name)) return kERR; |
|
// create new proxy object |
TP* pobj = new TP(interp, name.c_str()); |
// execute configure, delete command in case configure failed |
// Note: deleting the command will implicitely delete the object.. |
if (pobj->ClassCmdConfig(args) != kOK) { |
ClassCmdDelete(interp, name.c_str()); |
return kERR; |
} |
return kOK; |
} |
|
//------------------------------------------+----------------------------------- |
//! FIXME_docs |
|
template <class TP> |
inline void RtclClassOwned<TP>::CreateClass(Tcl_Interp* interp, |
const char* name, |
const std::string& type) |
{ |
RtclClassOwned<TP>* p = new RtclClassOwned<TP>(type); |
p->CreateClassCmd(interp, name); |
return; |
} |
|
} // end namespace Retro |
/.cvsignore
0,0 → 1,91
*.dep |
.
Property changes :
Added: svn:ignore
## -0,0 +1,33 ##
+*.dep_ghdl
+*.dep_isim
+*.dep_xst
+work-obj93.cf
+*.vcd
+*.ghw
+*.sav
+*.tmp
+*.exe
+ise
+xflow.his
+*.ngc
+*.ncd
+*.pcf
+*.bit
+*.msk
+isim
+isim.log
+isim.wdb
+fuse.log
+*_[sft]sim.vhd
+*_tsim.sdf
+*_xst.log
+*_tra.log
+*_twr.log
+*_map.log
+*_par.log
+*_pad.log
+*_bgn.log
+*_svn.log
+*_sum.log
+*_[dsft]sim.log
+*.dep