/[escript]/branches/arrexp_2137_win/escript/src/DataEmpty.h
ViewVC logotype

Contents of /branches/arrexp_2137_win/escript/src/DataEmpty.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2212 - (show annotations)
Wed Jan 14 00:15:00 2009 UTC (11 years, 5 months ago) by jfenwick
File MIME type: text/plain
File size: 4196 byte(s)
Executive summary:

This commit adds copy on write checks to operations involving shared data. 

Changes:

new #defines:
~~~~~~~~~~~~~
Data.cpp has ASSIGNMENT_MEANS_DEEPCOPY (defaults to undefined).
Defining this will put the data = operator back to making deep copies instead
of sharing data (now the default.)

Data:
~~~~~
. Added exclusiveWrite method to copy the underlying data if it is shared.
. Some operators which took python objects now call the c++ versions intead of duplicating code.

DataAbstract and offspring:
~~~~~~~~~~~~~~~~~~~~~~~~~~~
. Added method to determine whether the data is currently shared.
. Added getVectorRO to children of DataReady.
. Added getTagRO.

. Operations which modify values in place (or return modifiable pointers) now use
a macro to check for sharing. In the case where a modification attempt is detected, it throws an exception. In the future, I will enable this only for debugging.

. This shold not really have been required but the compiler was not choosing the use the const version as I would have liked. Besides, this makes things explict.

. Moved (and de-inlined) getVector in DataConstant (It was virtual in a parent class).

Unit tests:
~~~~~~~~~~~
Added both python and c++ unit tests to check known cases of sharing and "inplace"
modification operations.

General:
~~~~~~~~
Removed some commented out code.

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2008 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14
15 #if !defined escript_DataEmpty_20040726_H
16 #define escript_DataEmpty_20040726_H
17 #include "system_dep.h"
18
19 #include "DataReady.h"
20
21 namespace escript {
22
23 /**
24 \brief
25 Implements the DataAbstract interface for an empty Data object.
26
27 Description:
28 Implements the DataAbstract interface for an empty Data object.
29 */
30
31 class DataEmpty : public DataReady {
32 typedef DataReady parent;
33 public:
34
35 /**
36 \brief
37 Default constructor for DataEmpty.
38
39 Description:
40 Default constructor for DataEmpty.
41
42 */
43 ESCRIPT_DLL_API
44 DataEmpty();
45
46 /**
47 \brief
48 Destructor for DataEmpty.
49 */
50 ESCRIPT_DLL_API
51 virtual
52 ~DataEmpty();
53
54 /**
55 \brief
56 Return a textual representation of the Data object.
57 */
58 ESCRIPT_DLL_API
59 virtual
60 std::string
61 toString() const;
62
63 /**
64 \brief Return a deep copy of the current object.
65 */
66 ESCRIPT_DLL_API
67 virtual
68 DataAbstract*
69 deepCopy();
70
71
72 /**
73 \brief
74 Return the offset for the given sample.
75 NB: This will throw an exception as obviously an empty Data object contains no
76 samples. An implementation is required by parent DataAbstract class.
77 \param sampleNo - Input - Sample number.
78 \param dataPointNo - Input - data-point number.
79 */
80 ESCRIPT_DLL_API
81 virtual
82 DataTypes::ValueType::size_type
83 getPointOffset(int sampleNo,
84 int dataPointNo) const;
85
86 ESCRIPT_DLL_API
87 virtual
88 DataTypes::ValueType::size_type
89 getPointOffset(int sampleNo,
90 int dataPointNo);
91
92 // /**
93 /* \brief
94 Return a view into the data for the data point specified.
95 NB: This will throw an exception as obviously an empty Data object contains no
96 data points. An implementation is required by parent DataAbstract class.
97 \param sampleNo - Input - Sample number.
98 \param dataPointNo - Input - data-point number.*/
99 // */
100 // ESCRIPT_DLL_API
101 // virtual
102 // DataArrayView
103 // getDataPoint(int sampleNo,
104 // int dataPointNo);
105
106 /**
107 \brief
108 Return the number of doubles stored for the Data object.
109 As this is an empty Data object, this method will always return 0.
110 */
111 ESCRIPT_DLL_API
112 virtual
113 ValueType::size_type
114 getLength() const;
115
116 /**
117 \brief
118 Factory method that returns a newly created DataEmpty sliced from the
119 current Data object according to the specified region.
120 NB: This will throw an exception as obviously an empty Data object contains no
121 data to slice from. An implementation is required by parent DataAbstract class.
122 */
123 ESCRIPT_DLL_API
124 virtual
125 DataAbstract*
126 getSlice(const DataTypes::RegionType& region) const;
127
128 /**
129 \brief
130 Set the current Data object according to the specified slice from the
131 given input value.
132 NB: This will throw an exception as obviously an empty Data object contains no
133 data to slice to. An implementation is required by parent DataAbstract class.
134 \param value Input - Data to copy from
135 \param region Input - Region to copy.
136 */
137 ESCRIPT_DLL_API
138 virtual
139 void
140 setSlice(const DataAbstract* value,
141 const DataTypes::RegionType& region);
142
143
144 void
145 dump(const std::string fileName) const;
146
147 protected:
148
149 /**
150 \brief Provide access to underlying storage. Internal use only!
151 */
152 ESCRIPT_DLL_API
153 virtual DataTypes::ValueType&
154 getVector();
155
156 ESCRIPT_DLL_API
157 virtual const DataTypes::ValueType&
158 getVector() const;
159
160 ESCRIPT_DLL_API
161 virtual const DataTypes::ValueType&
162 getVectorRO() const;
163
164
165 private:
166
167 // /**
168 /* \brief
169 Throw a standard exception. This function is called if an attempt
170 is made to use functions of DataEmpty that are not valid.*/
171 // */
172 // void
173 // throwStandardException(const std::string& functionName) const;
174
175 };
176
177 } // end of namespace
178
179 #endif

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26