SST/macro
global_ptr_array.h
Go to the documentation of this file.
1 /*
2  * This file is part of SST/macroscale:
3  * The macroscale architecture simulator from the SST suite.
4  * Copyright (c) 2009 Sandia Corporation.
5  * This software is distributed under the BSD License.
6  * Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
7  * the U.S. Government retains certain rights in this software.
8  * For more information, see the LICENSE file in the top
9  * SST/macroscale directory.
10  */
11 
12 #ifndef SSTMAC_SOFTWARE_PROCESS_GLOBAL_PTR_ARRAY_H_INCLUDED
13 #define SSTMAC_SOFTWARE_PROCESS_GLOBAL_PTR_ARRAY_H_INCLUDED
14 
16 
17 namespace sstmac {
18 namespace sw {
19 
20 template<typename T, int N>
22 {
23 
24  protected:
25  typedef spkt_unordered_map<long, T*> val_map;
26  typedef T* Tptr;
27  val_map vals_[N];
28  T* init_;
29 
30  bool
31  check_init(process_context ptxt, int n = 0) {
32  if (n >= N) {
35  "sstmac_global*::check_init: trying to access index %d outside of array size %d",
36  n, N);
37  }
38  if (ptxt != process_context::none) {
39  if (vals_[n].find(ptxt) == vals_[n].end()) {
40  vals_[n][ptxt] = init_;
41  }
42  return true;
43  }
44  else {
45  return false;
46  }
47  }
48 
49  public:
50  typedef typename val_map::const_iterator const_iterator;
51 
52  explicit
54  init_(NULL) {
55  }
56 
57  explicit
59  init_(init) {
60  }
61 
62  virtual
64  }
65 
66  virtual T*&
67  get_val(int n = 0) const {
68  if (n >= N) {
71  "sstmac_global*::get_val: trying to access index %d outside of array size %d",
72  n, N);
73  }
74  process_context ptxt = current_context();
75  val_map& vals = const_cast<val_map&> (vals_[n]);
76  if (ptxt != process_context::none) {
77  typename val_map::iterator it = vals.find(ptxt);
78  if (it == vals.end()) {
79  T*& ret = vals[ptxt] = init_;
80  return ret;
81  }
82  else {
83  return it->second;
84  }
85  }
86  return const_cast<T*&> (init_);
87  }
88 
89  virtual std::string
90  to_string() const {
91  std::stringstream ss;
92  ss << get_val();
93  return ss.str();
94  }
95 
96  template<typename U>
97  T*&
99  T*& myval = get_val();
100  myval = (T*) b;
101  return myval;
102  }
103 
104  template<typename U>
105  T*&
106  operator=(U* b) {
107  T*& myval = get_val();
108  myval = (T*) b;
109  return myval;
110  }
111 
112  T*
114  Tptr& p = get_val();
115  return ++p;
116  }
117 
118  T*
120  Tptr& p = get_val();
121  return --p;
122  }
123 
124  T*
125  operator++(int dummy) {
126  Tptr& p = get_val();
127  return p++;
128  }
129 
130  T*
131  operator--(int dummy) {
132  Tptr& p = get_val();
133  return p--;
134  }
135 
136  template<typename U>
137  T*
138  operator+(const U& b) {
139  Tptr p = get_val();
140  return p + b;
141  }
142 
143  template<typename U>
144  T*
145  operator-(const U& b) {
146  Tptr p = get_val();
147  return p - b;
148  }
149 
150  operator char*() {
151  return (char*) get_val();
152  }
153 
154  operator int*() {
155  return (int*) get_val();
156  }
157 
158  operator long*() {
159  return (long*) get_val();
160  }
161 
162  operator void*() {
163  return (void*) get_val();
164  }
165 
166  operator const char*() const {
167  return (const char*) get_val();
168  }
169 
170  operator const int*() const {
171  return (const int*) get_val();
172  }
173 
174  operator const long*() const {
175  return (const long*) get_val();
176  }
177 
178  operator const void*() const {
179  return (const void*) get_val();
180  }
181 
182  T*&
184  return *(get_val());
185  }
186 
187  template<typename U>
188  bool
189  operator ==(const U& b) const {
190  T* myval = get_val();
191  T* otherval = (T*) b;
192  return myval == otherval;
193  }
194 
195  T*
197  return get_val();
198  }
199 
200  T*&
201  operator[](int idx) {
202  return get_val(idx);
203  }
204 
205  T*&
206  operator[](long idx) {
207  return get_val(idx);
208  }
209 
210 };
211 
212 }
213 }
214 #endif
215 
bool check_init(process_context ptxt, int n=0)
parallel_runtime * init()
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
#define spkt_throw_printf(exc, template_str,...)
Definition: errors.h:37
bool operator==(const software_id &a, const software_id &b)
Definition: software_id.h:45
T *& operator=(const sstmac_global_builtin< U > &b)
Error indicating some internal value was unexpected.
Definition: errors.h:83