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

Subversion Repositories w11

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

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

Line No. Rev Author Line
1 19 wfjm
// $Id: RtclContext.cpp 492 2013-02-24 22:14:47Z 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 19 wfjm
// 2013-02-03   481   1.0.3  use Rexception
17
// 2013-01-12   474   1.0.2  add FindProxy() method
18 10 wfjm
// 2011-03-12   368   1.0.1  drop fExitSeen, get exit handling right
19
// 2011-02-18   362   1.0    Initial version
20
// 2011-02-13   361   0.1    First draft
21
// ---------------------------------------------------------------------------
22
 
23
/*!
24
  \file
25 19 wfjm
  \version $Id: RtclContext.cpp 492 2013-02-24 22:14:47Z mueller $
26 10 wfjm
  \brief   Implemenation of RtclContext.
27
*/
28
 
29
#include <iostream>
30
 
31
#include "RtclContext.hpp"
32
 
33 19 wfjm
#include "librtools/Rexception.hpp"
34
 
35 10 wfjm
using namespace std;
36
 
37
/*!
38
  \class Retro::RtclContext
39
  \brief FIXME_docs
40
*/
41
 
42 19 wfjm
// all method definitions in namespace Retro
43
namespace Retro {
44 10 wfjm
 
45 19 wfjm
typedef std::pair<RtclContext::cset_it_t, bool>  cset_ins_t;
46
typedef std::pair<RtclContext::pset_it_t, bool>  pset_ins_t;
47
 
48 10 wfjm
RtclContext::xmap_t RtclContext::fMapContext;
49
 
50
//------------------------------------------+-----------------------------------
51
//! Default constructor
52
 
53
RtclContext::RtclContext(Tcl_Interp* interp)
54
  : fInterp(interp),
55
    fSetClass(),
56
    fSetProxy()
57
{}
58
 
59
//------------------------------------------+-----------------------------------
60
//! Destructor
61
 
62
RtclContext::~RtclContext()
63
{}
64
 
65
//------------------------------------------+-----------------------------------
66
//! FIXME_docs
67
 
68
void RtclContext::RegisterClass(RtclClassBase* pobj)
69
{
70
  cset_ins_t ret = fSetClass.insert(pobj);
71
  if (ret.second == false)                  // or use !(ret.second)
72 19 wfjm
    throw Rexception("RtclContext::RegisterClass()",
73
                     "Bad args: duplicate pointer");
74 10 wfjm
  return;
75
}
76
 
77
//------------------------------------------+-----------------------------------
78
//! FIXME_docs
79
 
80
void RtclContext::UnRegisterClass(RtclClassBase* pobj)
81
{
82
  fSetClass.erase(pobj);
83
  return;
84
}
85
 
86
//------------------------------------------+-----------------------------------
87
//! FIXME_docs
88
 
89
void RtclContext::RegisterProxy(RtclProxyBase* pobj)
90
{
91
  pset_ins_t ret = fSetProxy.insert(pobj);
92
  if (ret.second == false)                  // or use !(ret.second)
93 19 wfjm
    throw Rexception("RtclContext::RegisterProxy()",
94
                     "Bad args: duplicate pointer");
95 10 wfjm
  return;
96
}
97
 
98
//------------------------------------------+-----------------------------------
99
//! FIXME_docs
100
 
101
void RtclContext::UnRegisterProxy(RtclProxyBase* pobj)
102
{
103
  fSetProxy.erase(pobj);
104
  return;
105
}
106
 
107
//------------------------------------------+-----------------------------------
108
//! FIXME_docs
109
 
110
bool RtclContext::CheckProxy(RtclProxyBase* pobj)
111
{
112
  pset_it_t it = fSetProxy.find(pobj);
113
  return it != fSetProxy.end();
114
}
115
 
116
//------------------------------------------+-----------------------------------
117
//! FIXME_docs
118
 
119
bool RtclContext::CheckProxy(RtclProxyBase* pobj, const string& type)
120
{
121
  pset_it_t it = fSetProxy.find(pobj);
122
  if (it == fSetProxy.end()) return false;
123
  return (*it)->Type() == type;
124
}
125
 
126
//------------------------------------------+-----------------------------------
127
//! FIXME_docs
128
 
129
void RtclContext::ListProxy(std::vector<RtclProxyBase*>& list,
130
                            const std::string& type)
131
{
132
  list.clear();
133
  for (pset_it_t it = fSetProxy.begin(); it != fSetProxy.end(); it++) {
134
    if (type.length() == 0 || (*it)->Type()==type) {
135
      list.push_back(*it);
136
    }
137
  }
138
  return;
139
}
140
 
141
//------------------------------------------+-----------------------------------
142
//! FIXME_docs
143
 
144 19 wfjm
RtclProxyBase* RtclContext::FindProxy(const std::string& type,
145
                                      const std::string& name)
146
{
147
  for (pset_it_t it = fSetProxy.begin(); it != fSetProxy.end(); it++) {
148
    if (type.length() == 0 || (*it)->Type()==type) {
149
      const char* cmdname = Tcl_GetCommandName(fInterp, (*it)->Token());
150
      if (name == cmdname) return *it;
151
    }
152
  }
153
  return 0;
154
}
155
 
156
//------------------------------------------+-----------------------------------
157
//! FIXME_docs
158
 
159 10 wfjm
RtclContext& RtclContext::Find(Tcl_Interp* interp)
160
{
161
  RtclContext* pcntx = 0;
162
  xmap_it_t it = fMapContext.find(interp);
163
  if (it != fMapContext.end()) {
164
    pcntx = it->second;
165
  } else {
166
    pcntx = new RtclContext(interp);
167
    fMapContext.insert(xmap_val_t(interp, pcntx));
168
    Tcl_CreateExitHandler((Tcl_ExitProc*) ThunkTclExitProc, (ClientData) pcntx);
169
 
170
  }
171
  return *pcntx;
172
}
173
 
174
//------------------------------------------+-----------------------------------
175
//! FIXME_docs
176
 
177
// Note: tcl exit handlers are executed in inverse order of creation.
178
//       If Find() is called before any Class or Proxy cleanup handlers
179
//       are created the exit handler created in Find() will be called
180
//       last, when all map entries have been erased.
181
 
182
void RtclContext::ThunkTclExitProc(ClientData cdata)
183
{
184
  RtclContext* pcntx = (RtclContext*) cdata;
185
  if (pcntx->fSetClass.empty() && pcntx->fSetProxy.empty()) {
186
    delete pcntx;
187
  } else {
188
    cerr << "RtclContext::ThunkTclExitProc called when maps non-empty" << endl;
189
  }
190
  return;
191
}
192
 
193 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.