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

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

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 size: 2494 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 #include "DataEmpty.h"
16 #include "DataException.h"
17
18
19 namespace {
20
21
22 inline
23 void
24 throwStandardException(const std::string& functionName)
25 {
26 throw escript::DataException("Error - "+functionName+" function call invalid for DataEmpty.");
27 }
28
29
30 escript::DataTypes::ValueType dummy;
31
32 }
33
34 namespace escript {
35
36 DataEmpty::DataEmpty() :
37 parent(FunctionSpace(),DataTypes::scalarShape, true)
38 {
39
40 }
41
42 DataEmpty::~DataEmpty()
43 {
44 }
45
46 std::string
47 DataEmpty::toString() const
48 {
49 return "(Empty Data)";
50 }
51
52
53 DataAbstract*
54 DataEmpty::deepCopy()
55 {
56 return new DataEmpty();
57 }
58
59 DataTypes::ValueType::size_type
60 DataEmpty::getPointOffset(int sampleNo,
61 int dataPointNo) const
62 {
63 throwStandardException("getPointOffset");
64 return 0;
65 }
66
67 DataTypes::ValueType::size_type
68 DataEmpty::getPointOffset(int sampleNo,
69 int dataPointNo)
70 {
71 throwStandardException("getPointOffset");
72 return 0;
73 }
74
75 DataTypes::ValueType::size_type
76 DataEmpty::getLength() const
77 {
78 return 0;
79 }
80
81 DataAbstract*
82 DataEmpty::getSlice(const DataTypes::RegionType& region) const
83 {
84 throwStandardException("getSlice");
85 return 0;
86 }
87
88 void
89 DataEmpty::setSlice(const DataAbstract* value,
90 const DataTypes::RegionType& region)
91 {
92 throwStandardException("setSlice");
93 }
94
95
96
97 DataTypes::ValueType&
98 DataEmpty::getVector()
99 {
100 throwStandardException("getVector"); // always throws but the compiler doesn't know that.
101 return dummy; // dead code to stop the compiler complaining
102 }
103
104 const DataTypes::ValueType&
105 DataEmpty::getVector() const
106 {
107 throwStandardException("getVector"); // always throws but the compiler doesn't know that.
108 return dummy; // dead code to stop the compiler complaining
109 }
110
111 const DataTypes::ValueType&
112 DataEmpty::getVectorRO() const
113 {
114 throwStandardException("getVector"); // always throws but the compiler doesn't know that.
115 return dummy; // dead code to stop the compiler complaining
116 }
117
118
119 void
120 DataEmpty::dump(const std::string fileName) const
121 {
122 throw DataException("Error - Cannot dump() a DataEmpty object.");
123 }
124
125 } // end of namespace

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26