SCIRun  5.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Array1.h
Go to the documentation of this file.
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2009 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 
30 
31 ///
32 ///@file Array1.h
33 ///@brief Interface to dynamic 1D array class
34 ///
35 ///@author Steven G. Parker
36 /// Department of Computer Science
37 /// University of Utah
38 ///@date March 1994
39 ///
40 
41 #ifndef CORE_CONAINTERS_ARRAY1_H
42 #define CORE_CONAINTERS_ARRAY1_H 1
43 
44 #include <vector>
45 
47 
48 namespace SCIRun {
49 
50 template<class T>
51 class Array1 : public std::vector<T>
52 {
53 public:
54  typedef std::vector<T> my_base;
55 
56  Array1() {}
57  explicit Array1(size_t size) : my_base(size) {}
58 };
59 
60 template<class T> void Pio(Piostream& stream, Array1<T>& array);
61 
62 #define ARRAY1_VERSION 3
63 
64 template<class T>
65 void Pio(Piostream& stream, Array1<T>& array)
66 {
67  int version= stream.begin_class("Array1", ARRAY1_VERSION);
69  if (version < 3)
70  {
71  int sz;
72  Pio(stream,sz);
73  size = static_cast<size_type>(sz);
74  }
75  else
76  {
77  long long sz = static_cast<long long>(array.size());
78  Pio(stream,sz);
79  size = static_cast<size_type>(sz);
80  }
81 
82  if(stream.reading())
83  {
84  array.clear();
85  array.resize(size);
86  }
87 
88  if (stream.supports_block_io())
89  {
90  stream.block_io(&array[0],sizeof(T),size);
91  }
92  else
93  {
94  for(index_type i=0;i<size;i++)
95  Pio(stream, array[i]);
96  }
97  stream.end_class();
98 }
99 
100 template<class T>
101 void Pio(Piostream& stream, Array1<T>*& array)
102 {
103  if (stream.reading())
104  array=new Array1<T>;
105  Pio(stream, *array);
106 }
107 
108 } // End namespace SCIRun
109 
110 
111 #endif
112 
std::vector< T > my_base
Definition: Array1.h:54
virtual bool block_io(void *, size_t, size_t)
Definition: Persistent.h:174
bool reading() const
Definition: Persistent.h:164
virtual bool supports_block_io()
Definition: Persistent.h:171
Definition: Persistent.h:89
Array1(size_t size)
Definition: Array1.h:57
Array1()
Definition: Array1.h:56
virtual int begin_class(const std::string &name, int current_version)
Definition: Persistent.cc:143
Base class for persistent objects...
long long size_type
Definition: Types.h:40
void Pio(Piostream &stream, Array1< T > &array)
Definition: Array1.h:65
virtual void end_class()
Definition: Persistent.cc:178
long long index_type
Definition: Types.h:39
#define ARRAY1_VERSION
Definition: Array1.h:62
Definition: Array1.h:51
int size
Definition: eabLatVolData.py:2