timebuf.hh (7813:7338bc628489) | timebuf.hh (10200:1ab8753de4d8) |
---|---|
1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 35 unchanged lines hidden (view full) --- 44 int future; 45 unsigned size; 46 int _id; 47 48 char *data; 49 std::vector<char *> index; 50 unsigned base; 51 | 1/* 2 * Copyright (c) 2004-2005 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 35 unchanged lines hidden (view full) --- 44 int future; 45 unsigned size; 46 int _id; 47 48 char *data; 49 std::vector<char *> index; 50 unsigned base; 51 |
52 void valid(int idx) | 52 void valid(int idx) const |
53 { 54 assert (idx >= -past && idx <= future); 55 } 56 57 public: 58 friend class wire; 59 class wire 60 { --- 123 unchanged lines hidden (view full) --- 184 int ptr = base + future; 185 if (ptr >= (int)size) 186 ptr -= size; 187 (reinterpret_cast<T *>(index[ptr]))->~T(); 188 std::memset(index[ptr], 0, sizeof(T)); 189 new (index[ptr]) T; 190 } 191 | 53 { 54 assert (idx >= -past && idx <= future); 55 } 56 57 public: 58 friend class wire; 59 class wire 60 { --- 123 unchanged lines hidden (view full) --- 184 int ptr = base + future; 185 if (ptr >= (int)size) 186 ptr -= size; 187 (reinterpret_cast<T *>(index[ptr]))->~T(); 188 std::memset(index[ptr], 0, sizeof(T)); 189 new (index[ptr]) T; 190 } 191 |
192 T *access(int idx) | 192 protected: 193 //Calculate the index into this->index for element at position idx 194 //relative to now 195 inline int calculateVectorIndex(int idx) const |
193 { 194 //Need more complex math here to calculate index. 195 valid(idx); 196 197 int vector_index = idx + base; 198 if (vector_index >= (int)size) { 199 vector_index -= size; 200 } else if (vector_index < 0) { 201 vector_index += size; 202 } 203 | 196 { 197 //Need more complex math here to calculate index. 198 valid(idx); 199 200 int vector_index = idx + base; 201 if (vector_index >= (int)size) { 202 vector_index -= size; 203 } else if (vector_index < 0) { 204 vector_index += size; 205 } 206 |
207 return vector_index; 208 } 209 210 public: 211 T *access(int idx) 212 { 213 int vector_index = calculateVectorIndex(idx); 214 |
|
204 return reinterpret_cast<T *>(index[vector_index]); 205 } 206 207 T &operator[](int idx) 208 { | 215 return reinterpret_cast<T *>(index[vector_index]); 216 } 217 218 T &operator[](int idx) 219 { |
209 //Need more complex math here to calculate index. 210 valid(idx); | 220 int vector_index = calculateVectorIndex(idx); |
211 | 221 |
212 int vector_index = idx + base; 213 if (vector_index >= (int)size) { 214 vector_index -= size; 215 } else if (vector_index < 0) { 216 vector_index += size; 217 } 218 | |
219 return reinterpret_cast<T &>(*index[vector_index]); 220 } 221 | 222 return reinterpret_cast<T &>(*index[vector_index]); 223 } 224 |
225 const T &operator[] (int idx) const 226 { 227 int vector_index = calculateVectorIndex(idx); 228 229 return reinterpret_cast<const T &>(*index[vector_index]); 230 } 231 |
|
222 wire getWire(int idx) 223 { 224 valid(idx); 225 226 return wire(this, idx); 227 } 228 229 wire zero() --- 12 unchanged lines hidden --- | 232 wire getWire(int idx) 233 { 234 valid(idx); 235 236 return wire(this, idx); 237 } 238 239 wire zero() --- 12 unchanged lines hidden --- |