00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <Information.h>
00034 #include <ID.h>
00035 #include <Vector.h>
00036 #include <Matrix.h>
00037 #include <Tensor.h>
00038
00039 Information::Information()
00040 :theType(UnknownType),
00041 theID(0), theVector(0), theMatrix(0), theTensor(0)
00042 {
00043
00044 }
00045
00046 Information::Information(int val)
00047 :theType(IntType), theInt(val),
00048 theID(0), theVector(0), theMatrix(0), theTensor(0)
00049 {
00050
00051 }
00052
00053 Information::Information(double val)
00054 :theType(DoubleType), theDouble(val),
00055 theID(0), theVector(0), theMatrix(0), theTensor(0)
00056 {
00057
00058 }
00059
00060 Information::Information(const ID &val)
00061 :theType(IdType),
00062 theID(0), theVector(0), theMatrix(0), theTensor(0)
00063 {
00064
00065 theID = new ID(val);
00066
00067 if (theID == 0)
00068 g3ErrorHandler->warning("%s -- failed to allocate ID",
00069 "Information::Information");
00070 }
00071
00072 Information::Information(const Vector &val)
00073 :theType(VectorType),
00074 theID(0), theVector(0), theMatrix(0), theTensor(0)
00075 {
00076
00077 theVector = new Vector(val);
00078
00079 if (theVector == 0)
00080 g3ErrorHandler->warning("%s -- failed to allocate Vector",
00081 "Information::Information");
00082 }
00083
00084 Information::Information(const Matrix &val)
00085 :theType(MatrixType),
00086 theID(0), theVector(0), theMatrix(0), theTensor(0)
00087 {
00088
00089 theMatrix = new Matrix(val);
00090
00091 if (theMatrix == 0)
00092 g3ErrorHandler->warning("%s -- failed to allocate Matrix",
00093 "Information::Information");
00094 }
00095
00096 Information::Information(const Tensor &val)
00097 :theType(TensorType),
00098 theID(0), theVector(0), theMatrix(0), theTensor(0)
00099 {
00100
00101 theTensor = new Tensor(val);
00102
00103 if (theTensor == 0)
00104 g3ErrorHandler->warning("%s -- failed to allocate Tensor",
00105 "Information::Information");
00106 }
00107
00108 Information::~Information()
00109 {
00110 if (theID != 0)
00111 delete theID;
00112
00113 if (theVector != 0)
00114 delete theVector;
00115
00116 if (theMatrix != 0)
00117 delete theMatrix;
00118
00119 if (theTensor != 0)
00120 delete theTensor;
00121 }
00122
00123 int
00124 Information::setInt(int newInt)
00125 {
00126 theInt = newInt;
00127
00128 return 0;
00129 }
00130
00131 int
00132 Information::setDouble(double newDouble)
00133 {
00134 theDouble = newDouble;
00135
00136 return 0;
00137 }
00138
00139 int
00140 Information::setID(const ID &newID)
00141 {
00142 if (theID != 0) {
00143 *theID = newID;
00144 return 0;
00145 }
00146 else
00147 return -1;
00148 }
00149
00150 int
00151 Information::setVector(const Vector &newVector)
00152 {
00153 if (theVector != 0) {
00154 *theVector = newVector;
00155 return 0;
00156 }
00157 else
00158 return -1;
00159 }
00160
00161 int
00162 Information::setMatrix(const Matrix &newMatrix)
00163 {
00164 if (theMatrix != 0) {
00165 *theMatrix = newMatrix;
00166 return 0;
00167 }
00168 else
00169 return -1;
00170 }
00171
00172 int
00173 Information::setTensor(const Tensor &newTensor)
00174 {
00175 if (theTensor != 0) {
00176 *theTensor = newTensor;
00177 return 0;
00178 }
00179 else
00180 return -1;
00181 }
00182
00183 void
00184 Information::Print(ostream &s, int flag)
00185 {
00186 if (theType == IntType)
00187 s << theInt << " ";
00188 else if (theType == DoubleType)
00189 s << theDouble << " ";
00190 else if (theType == IdType && theID != 0)
00191 for (int i=0; i<theID->Size(); i++)
00192 s << (*theID)(i) << " ";
00193 else if (theType == VectorType && theVector != 0)
00194 for (int i=0; i<theVector->Size(); i++)
00195 s << (*theVector)(i) << " ";
00196 else if (theType == MatrixType && theMatrix != 0)
00197 s << *theMatrix;
00198 else if (theType == TensorType && theTensor != 0)
00199
00200
00201 s << "No Tensor output";
00202 else
00203 return;
00204 }