SST/macro
global_ptr.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_H_INCLUDED
13 #define SSTMAC_SOFTWARE_PROCESS_GLOBAL_PTR_H_INCLUDED
14 
16 
17 namespace sstmac {
18 namespace sw {
19 
20 template<typename T>
22 {
23 
24  protected:
25  typedef spkt_unordered_map<long, T*> val_map;
26  typedef T* Tptr;
27  val_map vals_;
28  T* init_;
29 
30  bool
32 
33  if (ptxt != process_context::none) {
34  if (vals_.find(ptxt) == vals_.end()) {
35  vals_[ptxt] = init_;
36  }
37  return true;
38  }
39  else {
40  return false;
41  }
42  }
43 
44  public:
45  typedef typename val_map::const_iterator const_iterator;
46 
47  explicit
49  init_(NULL) {
50  }
51 
52  explicit
54  init_(init) {
55  }
56 
57  virtual
59  }
60 
61  virtual T*&
62  get_val(int n = 0) const {
63 
64  process_context ptxt = current_context();
65  val_map& vals = const_cast<val_map&> (vals_);
66  if (ptxt != process_context::none) {
67  typename val_map::iterator it = vals.find(ptxt);
68  if (it == vals.end()) {
69  T*& ret = vals[ptxt] = init_;
70  return ret;
71  }
72  else {
73  return it->second;
74  }
75  }
76  return const_cast<T*&> (init_);
77  }
78 
79  virtual std::string
80  to_string() const {
81  std::stringstream ss;
82  ss << get_val();
83  return ss.str();
84  }
85 
86  template<typename U>
87  T*&
89  T*& myval = get_val();
90  myval = (T*) b;
91  return myval;
92  }
93 
94  template<typename U>
95  T*&
96  operator=(U* b) {
97  T*& myval = get_val();
98  myval = (T*) b;
99  return myval;
100  }
101 
102  T*
104  Tptr& p = get_val();
105  return ++p;
106  }
107 
108  T*
110  Tptr& p = get_val();
111  return --p;
112  }
113 
114  T*
115  operator++(int dummy) {
116  Tptr& p = get_val();
117  return p++;
118  }
119 
120  T*
121  operator--(int dummy) {
122  Tptr& p = get_val();
123  return p--;
124  }
125 
126  template<typename U>
127  T*
128  operator+(const U& b) {
129  Tptr p = get_val();
130  return p + b;
131  }
132 
133  template<typename U>
134  T*
135  operator-(const U& b) {
136  Tptr p = get_val();
137  return p - b;
138  }
139 
140  operator char*() {
141  return (char*) get_val();
142  }
143 
144  operator int*() {
145  return (int*) get_val();
146  }
147 
148  operator long*() {
149  return (long*) get_val();
150  }
151 
152  operator void*() {
153  return (void*) get_val();
154  }
155 
156  operator const char*() const {
157  return (const char*) get_val();
158  }
159 
160  operator const int*() const {
161  return (const int*) get_val();
162  }
163 
164  operator const long*() const {
165  return (const long*) get_val();
166  }
167 
168  operator const void*() const {
169  return (const void*) get_val();
170  }
171 
172  T&
174  return *(get_val());
175  }
176 
177  template<typename U>
178  bool
179  operator ==(const U& b) const {
180  T* myval = get_val();
181  T* otherval = (T*) b;
182  return myval == otherval;
183  }
184 
185  T*
187  return get_val();
188  }
189 
190  T&
191  operator[](int idx) {
192  T* arr = get_val();
193  return arr[idx];
194  }
195 
196  T&
197  operator[](long idx) {
198  T* arr = get_val();
199  return arr[idx];
200  }
201 
202  const_iterator
203  begin() const {
204  return vals_.begin();
205  }
206  const_iterator
207  end() const {
208  return vals_.end();
209  }
210 
211 };
212 
213 }
214 }
215 #endif
216 
val_map::const_iterator const_iterator
Definition: global_ptr.h:45
virtual T *& get_val(int n=0) const
Definition: global_ptr.h:62
virtual std::string to_string() const
Definition: global_ptr.h:80
bool check_init(process_context ptxt)
Definition: global_ptr.h:31
T *& operator=(const sstmac_global_builtin< U > &b)
Definition: global_ptr.h:88
parallel_runtime * init()
SUMI = Simulator unified messagine interface It is also the name for a solid ink in Japanese - i...
spkt_unordered_map< long, T * > val_map
Definition: global_ptr.h:25
bool operator==(const software_id &a, const software_id &b)
Definition: software_id.h:45