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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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