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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 10 wfjm
// $Id: RtclNameSet.cpp 374 2011-03-27 17:02:47Z mueller $
2
//
3
// Copyright 2011- 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
// 2011-02-20   363   1.0    Initial version
17
// ---------------------------------------------------------------------------
18
 
19
/*!
20
  \file
21
  \version $Id: RtclNameSet.cpp 374 2011-03-27 17:02:47Z mueller $
22
  \brief   Implemenation of RtclNameSet.
23
*/
24
 
25
// debug
26
#include <iostream>
27
 
28
#include <stdexcept>
29
 
30
#include "RtclNameSet.hpp"
31
 
32
using namespace std;
33
using namespace Retro;
34
 
35
/*!
36
  \class Retro::RtclNameSet
37
  \brief FIXME_docs
38
*/
39
 
40
typedef std::pair<Retro::RtclNameSet::nset_it_t, bool>  nset_ins_t;
41
 
42
//------------------------------------------+-----------------------------------
43
//! Default constructor
44
 
45
RtclNameSet::RtclNameSet()
46
  : fSet()
47
{}
48
 
49
//------------------------------------------+-----------------------------------
50
//! FIXME_docs
51
 
52
RtclNameSet::RtclNameSet(const std::string& nset)
53
  : fSet()
54
{
55
  size_t ibeg=0;
56
  while (true) {
57
    size_t iend = nset.find_first_of('|', ibeg);
58
    if (iend-ibeg > 0) {
59
      string name(nset, ibeg, iend-ibeg);
60
      nset_ins_t ret = fSet.insert(name);
61
        if (ret.second == false)                  // or use !(ret.second)
62
          throw logic_error(string("RtclNameSet::<ctor> duplicate name '") +
63
                            name + string("' in set '") + nset + string("'"));
64
    }
65
    if (iend == string::npos) break;
66
    ibeg = iend+1;
67
  }
68
}
69
 
70
//------------------------------------------+-----------------------------------
71
//! Destructor
72
 
73
RtclNameSet::~RtclNameSet()
74
{}
75
 
76
//------------------------------------------+-----------------------------------
77
//! FIXME_docs
78
 
79
bool RtclNameSet:: Check(Tcl_Interp* interp, std::string& rval,
80
                         const std::string& tval) const
81
{
82
  rval.clear();
83
  nset_cit_t it = fSet.lower_bound(tval);
84
 
85
  // no leading substring match
86
  if (it==fSet.end() || tval!=it->substr(0,tval.length())) {
87
    Tcl_AppendResult(interp, "-E: bad option \"", tval.c_str(),
88
                     "\": must be ", NULL);
89
    const char* delim = "";
90
    for (nset_cit_t it1=fSet.begin(); it1!=fSet.end(); it1++) {
91
      Tcl_AppendResult(interp, delim, it1->c_str(), NULL);
92
      delim = ",";
93
    }
94
    return false;
95
  }
96
 
97
  // check for ambiguous substring match
98
  if (tval != *it) {
99
    nset_cit_t it1 = it;
100
    it1++;
101
    if (it1!=fSet.end() && tval==it1->substr(0,tval.length())) {
102
      Tcl_AppendResult(interp, "-E: ambiguous option \"", tval.c_str(),
103
                       "\": must be ", NULL);
104
      const char* delim = "";
105
      for (it1=it; it1!=fSet.end() &&
106
             tval==it1->substr(0,tval.length()); it1++) {
107
        Tcl_AppendResult(interp, delim, it1->c_str(), NULL);
108
        delim = ",";
109
      }
110
      return false;
111
    }
112
  }
113
 
114
  rval = *it;
115
  return true;
116
}
117
 
118
//------------------------------------------+-----------------------------------
119
#if (defined(Retro_NoInline) || defined(Retro_RtclNameSet_NoInline))
120
#define inline
121
#include "RtclNameSet.ipp"
122
#undef  inline
123
#endif

powered by: WebSVN 2.1.0

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