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 10

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

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

powered by: WebSVN 2.1.0

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