Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
linearmemory.h
1 #pragma once
2 
3 #include <typeinfo>
4 
5 #include "coredefs.h"
6 #include "vector.h"
7 
8 namespace iu {
60 template<unsigned int Ndim = 1>
62 {
63 IU_ASSERT(Ndim > 0)
64 public:
67  size_(), stride_()
68  {
69  }
70 
75  size_(size)
76  {
77  computeStride();
78  }
79 
84  LinearMemory(const unsigned int& numel) :
85  size_()
86  {
87  size_[0] = numel;
88  computeStride();
89  }
94  bool sameType(const LinearMemory &from)
95  {
96  return typeid(from) == typeid(*this);
97  }
98 
100  virtual ~LinearMemory()
101  {
102  }
103 
105  unsigned int numel() const
106  {
107  return size_.numel();
108  }
109 
110 // /** Returns the number of elements saved in the buffer. (numel of buffer) */
111 // unsigned int length() const
112 // {
113 //#pragma message("LinearMemory::length() is deprecated and will be removed in the future. Use numel() instead.")
117 // return size_.numel();
118 // }
119 
121  Size<Ndim> size() const
122  {
123  return size_;
124  }
125 
128  {
129  return stride_;
130  }
131 
133  virtual size_t bytes() const
134  {
135  return 0;
136  }
137 
139  virtual unsigned int bitDepth() const
140  {
141  return 0;
142  }
143 
145  virtual bool onDevice() const
146  {
147  return false;
148  }
149 
151  friend std::ostream& operator<<(std::ostream & out,
152  LinearMemory const& linmem)
153  {
154  out << "LinearMemory: size=" << linmem.size() << " strides="
155  << linmem.stride() << " numel=" << linmem.numel() << " onDevice="
156  << linmem.onDevice();
157  return out;
158  }
159 
160 protected:
163 
166  {
167  for (unsigned int i = 0; i < Ndim; i++)
168  {
169  if (i == 0)
170  stride_[i] = 1;
171  else
172  stride_[i] = stride_[i - 1] * size_[i - 1];
173  }
174  }
175 
176 private:
178  Size<Ndim> stride_;
179 
180 private:
182  LinearMemory(const LinearMemory&);
184  LinearMemory& operator=(const LinearMemory&);
185 };
186  // end of Memory Management// end of Linear Memory
189 }// namespace iu
190 
191 
void computeStride()
Definition: linearmemory.h:165
friend std::ostream & operator<<(std::ostream &out, LinearMemory const &linmem)
Definition: linearmemory.h:151
virtual size_t bytes() const
Definition: linearmemory.h:133
unsigned int numel() const
Definition: linearmemory.h:105
LinearMemory(const unsigned int &numel)
Definition: linearmemory.h:84
LinearMemory()
Definition: linearmemory.h:66
Base class for linear memory classes.
Definition: linearmemory.h:61
LinearMemory(const Size< Ndim > &size)
Definition: linearmemory.h:74
Size< Ndim > size() const
Definition: linearmemory.h:121
virtual ~LinearMemory()
Definition: linearmemory.h:100
virtual bool onDevice() const
Definition: linearmemory.h:145
virtual unsigned int bitDepth() const
Definition: linearmemory.h:139
bool sameType(const LinearMemory &from)
Definition: linearmemory.h:94
Size< Ndim > stride() const
Definition: linearmemory.h:127
Main class for N-dimensional unsigned int vectors (size vectors).
Definition: vector.h:460
Size< Ndim > size_
Definition: linearmemory.h:162