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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [src/] [librtcltools/] [RtclGetList.cpp] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 21 wfjm
// $Id: RtclGetList.cpp 516 2013-05-05 21:24:52Z mueller $
2 19 wfjm
//
3
// Copyright 2013- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4
//
5
// This program is free software; you may redistribute and/or modify it under
6
// the terms of the GNU General Public License as published by the Free
7
// Software Foundation, either version 2, or at your option any later version.
8
//
9
// This program is distributed in the hope that it will be useful, but
10
// WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
11
// or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12
// for complete details.
13
// 
14
// Revision History: 
15
// Date         Rev Version  Comment
16
// 2013-02-12   487   1.0    Initial version
17
// ---------------------------------------------------------------------------
18
 
19
/*!
20
  \file
21 21 wfjm
  \version $Id: RtclGetList.cpp 516 2013-05-05 21:24:52Z mueller $
22 19 wfjm
  \brief   Implemenation of class RtclGetList.
23
*/
24
 
25
#include <iostream>
26
 
27
#include "librtools/Rexception.hpp"
28
 
29
#include "RtclGet.hpp"
30
#include "RtclGetList.hpp"
31
 
32
using namespace std;
33
 
34
/*!
35
  \class Retro::RtclGetList
36
  \brief FIXME_docs
37
*/
38
 
39
// all method definitions in namespace Retro
40
namespace Retro {
41
 
42
//------------------------------------------+-----------------------------------
43
//! FIXME_docs
44
 
45
RtclGetList::RtclGetList()
46
  : fMap()
47
{}
48
 
49
//------------------------------------------+-----------------------------------
50
//! FIXME_docs
51
 
52
RtclGetList::~RtclGetList()
53
{
54
  for (map_cit_t it=fMap.begin(); it != fMap.end(); it++) {
55
    delete (it->second);
56
  }
57
}
58
 
59
//------------------------------------------+-----------------------------------
60
//! FIXME_docs
61
 
62
void RtclGetList::Add(const std::string& name, RtclGetBase* pget)
63
{
64
  typedef std::pair<Retro::RtclGetList::map_it_t, bool>  map_ins_t;
65
  map_ins_t ret = fMap.insert(map_val_t(name, pget));
66
  if (ret.second == false)
67 21 wfjm
     throw Rexception("RtclGetList::Add:",
68
                      string("Bad args: duplicate name: '") + name + "'");
69 19 wfjm
  return;
70
}
71
 
72
//------------------------------------------+-----------------------------------
73
//! FIXME_docs
74
 
75
int RtclGetList::M_get(RtclArgs& args)
76
{
77
  string pname;
78
  if (!args.GetArg("pname", pname)) return TCL_ERROR;
79
 
80
  Tcl_Interp* interp = args.Interp();
81
  map_cit_t it = fMap.lower_bound(pname);
82
 
83
  // complain if not found
84
  if (it == fMap.end() || pname != it->first.substr(0,pname.length())) {
85
    Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(),
86
                     "': must be ", NULL);
87
    const char* delim = "";
88
    for (map_cit_t it1=fMap.begin(); it1!=fMap.end(); it1++) {
89
      Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL);
90
      delim = ",";
91
    }
92
    return TCL_ERROR;
93
  }
94
 
95
  // check for ambiguous substring match
96
  map_cit_t it1 = it;
97
  it1++;
98
  if (it1!=fMap.end() && pname==it1->first.substr(0,pname.length())) {
99
    Tcl_AppendResult(interp, "-E: ambiguous property name '", pname.c_str(),
100
                     "': must be ", NULL);
101
    const char* delim = "";
102
    for (it1=it; it1!=fMap.end() &&
103
           pname==it1->first.substr(0,pname.length()); it1++) {
104
      Tcl_AppendResult(interp, delim, it1->first.c_str(), NULL);
105
      delim = ",";
106
    }
107
 
108
    return TCL_ERROR;
109
  }
110
 
111
  if (!args.AllDone()) return TCL_ERROR;
112
 
113
  args.SetResult((it->second)->operator()());
114
  return TCL_OK;
115
}
116
 
117
} // end namespace Retro

powered by: WebSVN 2.1.0

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