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

Subversion Repositories w11

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 wfjm
// $Id: RtclGetList.cpp 584 2014-08-22 19:38:12Z mueller $
2 19 wfjm
//
3 27 wfjm
// Copyright 2013-2014 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4 19 wfjm
//
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 27 wfjm
// 2014-08-22   584   1.0.1  use nullptr
17 19 wfjm
// 2013-02-12   487   1.0    Initial version
18
// ---------------------------------------------------------------------------
19
 
20
/*!
21
  \file
22 27 wfjm
  \version $Id: RtclGetList.cpp 584 2014-08-22 19:38:12Z mueller $
23 19 wfjm
  \brief   Implemenation of class RtclGetList.
24
*/
25
 
26
#include <iostream>
27
 
28
#include "librtools/Rexception.hpp"
29
 
30
#include "RtclGet.hpp"
31
#include "RtclGetList.hpp"
32
 
33
using namespace std;
34
 
35
/*!
36
  \class Retro::RtclGetList
37
  \brief FIXME_docs
38
*/
39
 
40
// all method definitions in namespace Retro
41
namespace Retro {
42
 
43
//------------------------------------------+-----------------------------------
44
//! FIXME_docs
45
 
46
RtclGetList::RtclGetList()
47
  : fMap()
48
{}
49
 
50
//------------------------------------------+-----------------------------------
51
//! FIXME_docs
52
 
53
RtclGetList::~RtclGetList()
54
{
55
  for (map_cit_t it=fMap.begin(); it != fMap.end(); it++) {
56
    delete (it->second);
57
  }
58
}
59
 
60
//------------------------------------------+-----------------------------------
61
//! FIXME_docs
62
 
63
void RtclGetList::Add(const std::string& name, RtclGetBase* pget)
64
{
65
  typedef std::pair<Retro::RtclGetList::map_it_t, bool>  map_ins_t;
66
  map_ins_t ret = fMap.insert(map_val_t(name, pget));
67
  if (ret.second == false)
68 21 wfjm
     throw Rexception("RtclGetList::Add:",
69
                      string("Bad args: duplicate name: '") + name + "'");
70 19 wfjm
  return;
71
}
72
 
73
//------------------------------------------+-----------------------------------
74
//! FIXME_docs
75
 
76
int RtclGetList::M_get(RtclArgs& args)
77
{
78
  string pname;
79
  if (!args.GetArg("pname", pname)) return TCL_ERROR;
80
 
81
  Tcl_Interp* interp = args.Interp();
82
  map_cit_t it = fMap.lower_bound(pname);
83
 
84
  // complain if not found
85
  if (it == fMap.end() || pname != it->first.substr(0,pname.length())) {
86
    Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(),
87 27 wfjm
                     "': must be ", nullptr);
88 19 wfjm
    const char* delim = "";
89
    for (map_cit_t it1=fMap.begin(); it1!=fMap.end(); it1++) {
90 27 wfjm
      Tcl_AppendResult(interp, delim, it1->first.c_str(), nullptr);
91 19 wfjm
      delim = ",";
92
    }
93
    return TCL_ERROR;
94
  }
95
 
96
  // check for ambiguous substring match
97
  map_cit_t it1 = it;
98
  it1++;
99
  if (it1!=fMap.end() && pname==it1->first.substr(0,pname.length())) {
100
    Tcl_AppendResult(interp, "-E: ambiguous property name '", pname.c_str(),
101 27 wfjm
                     "': must be ", nullptr);
102 19 wfjm
    const char* delim = "";
103
    for (it1=it; it1!=fMap.end() &&
104
           pname==it1->first.substr(0,pname.length()); it1++) {
105 27 wfjm
      Tcl_AppendResult(interp, delim, it1->first.c_str(), nullptr);
106 19 wfjm
      delim = ",";
107
    }
108
 
109
    return TCL_ERROR;
110
  }
111
 
112
  if (!args.AllDone()) return TCL_ERROR;
113
 
114
  args.SetResult((it->second)->operator()());
115
  return TCL_OK;
116
}
117
 
118
} // end namespace Retro

powered by: WebSVN 2.1.0

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