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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [src/] [librlink/] [RlinkAddrMap.cpp] - Blame information for rev 33

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 wfjm
// $Id: RlinkAddrMap.cpp 603 2014-11-09 22:50:26Z 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.2  use Rexception
17 15 wfjm
// 2011-11-28   434   1.0.1  Print(): use proper cast for lp64 compatibility
18 10 wfjm
// 2011-03-06   367   1.0    Initial version
19
// 2011-03-05   366   0.1    First draft
20
// ---------------------------------------------------------------------------
21
 
22
/*!
23
  \file
24 27 wfjm
  \version $Id: RlinkAddrMap.cpp 603 2014-11-09 22:50:26Z mueller $
25 10 wfjm
  \brief   Implemenation of class RlinkAddrMap.
26
 */
27
 
28
#include <algorithm>
29
 
30
#include "RlinkAddrMap.hpp"
31
 
32
#include "librtools/RosFill.hpp"
33
#include "librtools/RosPrintf.hpp"
34 19 wfjm
#include "librtools/Rexception.hpp"
35 10 wfjm
 
36
using namespace std;
37
 
38
/*!
39
  \class Retro::RlinkAddrMap
40 19 wfjm
  \brief FIXME_docs
41 10 wfjm
*/
42
 
43 19 wfjm
// all method definitions in namespace Retro
44
namespace Retro {
45
 
46 10 wfjm
//------------------------------------------+-----------------------------------
47
//! Default constructor
48
 
49
RlinkAddrMap::RlinkAddrMap()
50
  : fNameMap(),
51
    fAddrMap(),
52
    fMaxLength(0)
53
{}
54
 
55
//------------------------------------------+-----------------------------------
56
//! Destructor
57
 
58
RlinkAddrMap::~RlinkAddrMap()
59
{}
60
 
61
//------------------------------------------+-----------------------------------
62
//! FIXME_docs
63
 
64
void RlinkAddrMap::Clear()
65
{
66
  fNameMap.clear();
67
  fAddrMap.clear();
68
  return;
69
}
70
 
71
//------------------------------------------+-----------------------------------
72
//! FIXME_docs
73
 
74
bool RlinkAddrMap::Insert(const std::string& name, uint16_t addr)
75
{
76
  if (fNameMap.find(name) != fNameMap.end()) return false;
77
  if (fAddrMap.find(addr) != fAddrMap.end()) return false;
78
 
79
  fNameMap.insert(nmap_val_t(name, addr));
80
  fAddrMap.insert(amap_val_t(addr, name));
81
  fMaxLength = max(fMaxLength, name.length());
82
 
83
  return true;
84
}
85
 
86
//------------------------------------------+-----------------------------------
87
//! FIXME_docs
88
 
89
bool RlinkAddrMap::Erase(const std::string& name)
90
{
91
  nmap_cit_t it = fNameMap.find(name);
92
  if (it == fNameMap.end()) return false;
93
 
94
  fMaxLength = 0;                           // force recalculate
95
  if (fNameMap.erase(name) == 0)
96 19 wfjm
    throw Rexception("RlinkAddrMap::Erase()",
97
                     "BugCheck: fNameMap erase failed");
98 10 wfjm
  if (fAddrMap.erase(it->second) == 0)
99 19 wfjm
    throw Rexception("RlinkAddrMap::Erase()",
100
                     "BugCheck: fAddrMap erase failed");
101 10 wfjm
 
102
  return true;
103
}
104
 
105
//------------------------------------------+-----------------------------------
106
//! FIXME_docs
107
 
108
bool RlinkAddrMap::Erase(uint16_t addr)
109
{
110
  amap_cit_t it = fAddrMap.find(addr);
111
  if (it == fAddrMap.end()) return false;
112
 
113
  fMaxLength = 0;                           // force recalculate
114
  if (fAddrMap.erase(addr) == 0)
115 19 wfjm
    throw Rexception("RlinkAddrMap::Erase()",
116
                     "BugCheck: fAddrMap erase failed");
117 10 wfjm
  if (fNameMap.erase(it->second) == 0)
118 19 wfjm
    throw Rexception("RlinkAddrMap::Erase()",
119
                     "BugCheck: fNameMap erase failed");
120 10 wfjm
 
121
  return true;
122
}
123
 
124
//------------------------------------------+-----------------------------------
125
//! FIXME_docs
126
 
127
bool RlinkAddrMap::Find(const std::string& name, uint16_t& addr) const
128
{
129
  nmap_cit_t it = fNameMap.find(name);
130
  if (it == fNameMap.end()) return false;
131
 
132
  addr = it->second;
133
 
134
  return true;
135
}
136
 
137
//------------------------------------------+-----------------------------------
138
//! FIXME_docs
139
 
140
bool RlinkAddrMap::Find(uint16_t addr, std::string& name) const
141
{
142
  amap_cit_t it = fAddrMap.find(addr);
143
  if (it == fAddrMap.end()) return false;
144
 
145
  name = it->second;
146
 
147
  return true;
148
}
149
 
150
//------------------------------------------+-----------------------------------
151
//! FIXME_docs
152
 
153
size_t RlinkAddrMap::MaxNameLength() const
154
{
155
  if (fMaxLength == 0) {
156
    for (amap_cit_t it=fAddrMap.begin(); it!=fAddrMap.end(); it++) {
157
      fMaxLength = max(fMaxLength, (it->second).length());
158
    }
159
  }
160
  return fMaxLength;
161
}
162
 
163
//------------------------------------------+-----------------------------------
164
//! FIXME_docs
165
 
166
void RlinkAddrMap::Print(std::ostream& os, int ind) const
167
{
168 15 wfjm
  size_t maxlen = max(((size_t) 6), MaxNameLength());
169 10 wfjm
 
170
  RosFill bl(ind);
171
  for (amap_cit_t it=fAddrMap.begin(); it!=fAddrMap.end(); it++) {
172
    os << bl << RosPrintf((it->second).c_str(), "-s",maxlen)
173 27 wfjm
       << " : " << RosPrintf(it->first, "$x0", 6)
174 10 wfjm
       << "  " << RosPrintf(it->first, "o0", 6) << endl;
175
  }
176
 
177
  return;
178
}
179
 
180
//------------------------------------------+-----------------------------------
181
//! FIXME_docs
182
 
183
void RlinkAddrMap::Dump(std::ostream& os, int ind, const char* text) const
184
{
185
  RosFill bl(ind);
186
  os << bl << (text?text:"--") << "RlinkAddrMap @ " << this << endl;
187
  Print(os,ind+2);
188
  return;
189
}
190
 
191 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.