w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
RtclSetList.cpp
Go to the documentation of this file.
1// $Id: RtclSetList.cpp 1186 2019-07-12 17:49:59Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2018 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2018-12-01 1076 1.2 use unique_ptr
8// 2018-11-16 1070 1.1.1 use auto; use emplace,make_pair; use range loop
9// 2015-01-08 631 1.1 add Clear(), add '?' (key list)
10// 2014-08-22 584 1.0.1 use nullptr
11// 2013-02-12 487 1.0 Initial version
12// ---------------------------------------------------------------------------
13
18#include <iostream>
19
21
22#include "RtclSet.hpp"
23#include "RtclSetList.hpp"
24#include "RtclOPtr.hpp"
25
26using namespace std;
27
33// all method definitions in namespace Retro
34namespace Retro {
35
36//------------------------------------------+-----------------------------------
38
40 : fMap()
41{}
42
43//------------------------------------------+-----------------------------------
45
47{}
48
49//------------------------------------------+-----------------------------------
51
52void RtclSetList::Add(const std::string& name, set_uptr_t&& upset)
53{
54 auto ret = fMap.emplace(make_pair(name, move(upset)));
55 if (ret.second == false)
56 throw Rexception("RtclSetList::Add:",
57 string("Bad args: duplicate name: '") + name + "'");
58 return;
59}
60
61//------------------------------------------+-----------------------------------
63
65{
66 fMap.clear();
67 return;
68}
69
70//------------------------------------------+-----------------------------------
72
74{
75 Tcl_Interp* interp = args.Interp();
76 string pname;
77 if (!args.GetArg("pname", pname)) return TCL_ERROR;
78
79 if (pname == "?") {
80 if (!args.AllDone()) return TCL_ERROR;
81 RtclOPtr rlist(Tcl_NewListObj(0,nullptr));
82 for (const auto& kv : fMap) {
83 RtclOPtr pele(Tcl_NewStringObj(kv.first.c_str(), -1));
84 Tcl_ListObjAppendElement(nullptr, rlist, pele);
85 }
86 Tcl_SetObjResult(interp, rlist);
87 return TCL_OK;
88 }
89
90 auto it = fMap.lower_bound(pname);
91
92 // complain if not found
93 if (it == fMap.end() || pname != it->first.substr(0,pname.length())) {
94 Tcl_AppendResult(interp, "-E: unknown property '", pname.c_str(),
95 "': must be ", nullptr);
96 const char* delim = "";
97 for (auto& o: fMap) {
98 Tcl_AppendResult(interp, delim, o.first.c_str(), nullptr);
99 delim = ",";
100 }
101 return TCL_ERROR;
102 }
103
104 // check for ambiguous substring match
105 auto it1 = it;
106 it1++;
107 if (it1!=fMap.end() && pname==it1->first.substr(0,pname.length())) {
108 Tcl_AppendResult(interp, "-E: ambiguous property name '", pname.c_str(),
109 "': must be ", nullptr);
110 const char* delim = "";
111 for (it1=it; it1!=fMap.end() &&
112 pname==it1->first.substr(0,pname.length()); it1++) {
113 Tcl_AppendResult(interp, delim, it1->first.c_str(), nullptr);
114 delim = ",";
115 }
116
117 return TCL_ERROR;
118 }
119
120 Tcl_Obj* pobj;
121 if (!args.GetArg("val", pobj)) return TCL_ERROR;
122 if (!args.AllDone()) return TCL_ERROR;
123
124 try {
125 (it->second)->operator()(args);
126 } catch (Rexception& e) {
127 Tcl_AppendResult(args.Interp(), "-E: ", e.ErrMsg().Text().c_str(), nullptr);
128 return TCL_ERROR;
129 } catch (exception& e) {
130 Tcl_AppendResult(args.Interp(), "-E: ", e.what(), nullptr);
131 return TCL_ERROR;
132 }
133
134 return TCL_OK;
135}
136
137} // end namespace Retro
const std::string & Text() const
FIXME_docs.
Definition: RerrMsg.ipp:47
FIXME_docs.
Definition: Rexception.hpp:29
virtual const char * what() const noexcept
FIXME_docs.
Definition: Rexception.cpp:81
const RerrMsg & ErrMsg() const
FIXME_docs.
Definition: Rexception.ipp:20
FIXME_docs.
Definition: RtclArgs.hpp:41
bool GetArg(const char *name, Tcl_Obj *&pval)
FIXME_docs.
Definition: RtclArgs.cpp:114
Tcl_Interp * Interp() const
FIXME_docs.
Definition: RtclArgs.ipp:28
bool AllDone()
FIXME_docs.
Definition: RtclArgs.cpp:447
Implemenation (inline) of RtclOPtr.
Definition: RtclOPtr.hpp:23
virtual ~RtclSetList()
FIXME_docs.
Definition: RtclSetList.cpp:46
void Add(const std::string &name, set_uptr_t &&upset)
FIXME_docs.
Definition: RtclSetList.cpp:52
void Clear()
FIXME_docs.
Definition: RtclSetList.cpp:64
int M_set(RtclArgs &args)
FIXME_docs.
Definition: RtclSetList.cpp:73
std::unique_ptr< RtclSetBase > set_uptr_t
Definition: RtclSetList.hpp:37
RtclSetList()
FIXME_docs.
Definition: RtclSetList.cpp:39
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47