1 /*******************************************************************/ 2 /* XDMF */ 3 /* eXtensible Data Model and Format */ 4 /* */ 5 /* Id : Id */ 6 /* Date : $Date$ */ 7 /* Version : $Revision$ */ 8 /* */ 9 /* Author: */ 10 /* Jerry A. Clarke */ 11 /* clarke@arl.army.mil */ 12 /* US Army Research Laboratory */ 13 /* Aberdeen Proving Ground, MD */ 14 /* */ 15 /* Copyright @ 2002 US Army Research Laboratory */ 16 /* All Rights Reserved */ 17 /* See Copyright.txt or http://www.arl.hpc.mil/ice for details */ 18 /* */ 19 /* This software is distributed WITHOUT ANY WARRANTY; without */ 20 /* even the implied warranty of MERCHANTABILITY or FITNESS */ 21 /* FOR A PARTICULAR PURPOSE. See the above copyright notice */ 22 /* for more information. */ 23 /* */ 24 /*******************************************************************/ 25 #ifndef __XdmfDataItem_h 26 #define __XdmfDataItem_h 27 28 #include "XdmfElement.h" 29 30 namespace xdmf2 31 { 32 33 class XdmfDataDesc; 34 class XdmfArray; 35 class XdmfValues; 36 37 #define XDMF_FORMAT_XML 0 38 #define XDMF_FORMAT_HDF 1 39 #define XDMF_FORMAT_MYSQL 2 40 #define XDMF_FORMAT_BINARY 3 41 42 // Organizations 43 #define XDMF_ITEM_UNIFORM 0x00 44 #define XDMF_ITEM_HYPERSLAB 0x01 45 #define XDMF_ITEM_COORDINATES 0x02 46 #define XDMF_ITEM_FUNCTION 0x03 47 #define XDMF_ITEM_COLLECTION 0x14 48 #define XDMF_ITEM_TREE 0x15 49 50 #define XDMF_ITEM_MASK 0xF0 // Evaluates to a Single Array ? 51 52 53 54 //! Data Container Object. 55 /*! 56 An XdmfDataItem is a container for data. It is of one of three types : 57 \verbatim 58 Uniform ...... A single DataStructure 59 HyperSlab .... A DataTransform that Subsamples some DataStructure 60 Coordinates .. A DataTransform that Subsamples via Parametric Coordinates 61 Function ..... A DataTransform described by some function 62 Collection ... Contains an Array of 1 or more DataStructures or DataTransforms 63 Tree ......... A Hierarchical group of other DataItems 64 \endverbatim 65 66 If not specified in the "ItemType" a Uniform item is assumed. 67 A Uniform DataItem is a XdmfDataStructure or an XdmfDataTransform. Both 68 XdmfDataStructure and XdmfDataTransform are maintined for backwards compatibility. 69 70 A Uniform XdmfDataItem represents an XdmfArray in XML. 71 DataItems have an optional name. Rank is also optional since it can be determined from the dimensions. 72 Dimensions are listed with the slowest varying dimension first. (i.e. KDim JDim IDim). Type is 73 "Char | Float | Int | Compound" with the default being Float. Precision is BytesPerElement and defaults to 74 4 for Ints and Floats. Format is any supported XDMF format but usually XML | HDF. 75 Examples : 76 \verbatim 77 <!-- Fully Qualified --> 78 <DataItem Name="MyDataItem" 79 Rank="3" Dimensions="2 3 4" 80 Type="Float" Precision="8" 81 Format="XML> 82 0 1 2 3 83 4 5 6 7 84 8 9 10 11 85 86 0 1 2 3 87 4 5 6 7 88 8 9 10 11 89 </DataItem> 90 <!-- Minimalist --> 91 <DataItem Dimensions="3"> 92 1 2 3 93 </DataItem> 94 95 96 XML Element : DataItem 97 XML Attribute : Name = Any String 98 XML Attribute : ItemType = Uniform* | Collection | Tree | HyperSlab | Coordinates | Function 99 XML Attribute : Dimensions = K J I 100 XML Attribute : NumberType = Float* | Int | UInt | Char | UChar 101 XML Attribute : Precision = 1 | 4 | 8 102 XML Attribute : Format = XML* | HDF 103 \endverbatim 104 */ 105 106 class XDMF_EXPORT XdmfDataItem : public XdmfElement { 107 108 public: 109 XdmfDataItem(); 110 virtual ~XdmfDataItem(); 111 GetClassName()112 XdmfConstString GetClassName() { return ( "XdmfDataItem" ) ; }; 113 114 //! Get the data values access object 115 XdmfGetValueMacro(Values, XdmfValues *); 116 117 //! Get the format of the data. Usually XML | HDF 118 XdmfGetValueMacro(Format, XdmfInt32); 119 //! Set the format of the data. Usually XML | HDF. Default is XML. 120 XdmfSetValueMacro(Format, XdmfInt32); 121 122 //! Insert an Element 123 XdmfInt32 Insert(XdmfElement *Child); 124 //! Tells the DataItem is it owns the Array and is thus allowed to delete it. 125 XdmfSetValueMacro(ArrayIsMine, XdmfInt32); 126 //! Get the Value it the DataItem owns the Array 127 XdmfGetValueMacro(ArrayIsMine, XdmfInt32); 128 129 //! Update Structure From XML (INPUT) 130 XdmfInt32 UpdateInformation(); 131 132 //! Update Structre and Values potentially reading Heavy Data (INPUT) 133 XdmfInt32 Update(); 134 135 //! Update the DOM (OUTPUT) 136 XdmfInt32 Build(); 137 138 //! Get the Internal XdmfDataDesc 139 XdmfGetValueMacro(DataDesc, XdmfDataDesc *); 140 141 //! Set the XdmfDataDesc. 142 XdmfInt32 SetDataDesc(XdmfDataDesc *DataDesc); 143 144 //! Get the Internal Array 145 XdmfArray *GetArray(XdmfInt32 Create=1); 146 147 //! Set the Array. Also sets ArrayIsMine = 0 148 XdmfInt32 SetArray(XdmfArray *Array); 149 150 //! Convenience Function to access Array 151 /*! The more robust access is via : 152 \verbatim 153 array = XdmfDataItem->GetArray(); 154 array->GetValues(....) 155 \endverbatim 156 */ 157 XdmfString GetDataValues( XdmfInt64 Index = 0, 158 XdmfInt64 NumberOfValues = 0, 159 XdmfInt64 ArrayStride = 1); 160 161 //! Convenience Function to access Array 162 /*! The more robust access is via : 163 \verbatim 164 array = XdmfDataItem->GetArray(); 165 array->SetValues(....) 166 \endverbatim 167 */ 168 XdmfInt32 SetDataValues( XdmfInt64 Index, XdmfConstString Values, 169 XdmfInt64 ArrayStride = 1, 170 XdmfInt64 ValuesStride = 1 ); 171 172 //! Get Rank of the Dimensions 173 XdmfInt32 GetRank(); 174 175 //! Set the Shape (Rank and Dimensions) 176 XdmfInt32 SetShape(XdmfInt32 Rank, XdmfInt64 *Dimensions); 177 //! Returns Rank and Fills in the Dimensions 178 XdmfInt32 GetShape(XdmfInt64 *Dimensions); 179 //! Returns Shape as String 180 XdmfConstString GetShapeAsString(); 181 182 //! Convenience Function GetDimensions()183 XdmfConstString GetDimensions(){return this->GetShapeAsString();}; 184 //! Convenience Function SetDimensions(XdmfInt32 Rank,XdmfInt64 * Dimensions)185 XdmfInt32 SetDimensions(XdmfInt32 Rank, XdmfInt64 *Dimensions){return this->SetShape(Rank, Dimensions);}; 186 //! Convenience Function 187 XdmfInt32 SetDimensionsFromString(XdmfConstString Dimensions); 188 //! Set the name of the Heavy Data Set (if applicable) 189 XdmfSetStringMacro(HeavyDataSetName); 190 //! Get the name of the Heavy Data Set (if applicable) 191 XdmfGetValueMacro(HeavyDataSetName, XdmfConstString); 192 //! Copy Information from Another DataItem 193 XdmfInt32 Copy(XdmfElement *Source); 194 //! Set the Type. One of : XDMF_ITEM_UNIFORM, XDMF_ITEM_COLLECTION, XDMF_ITEM_TREE 195 XdmfSetValueMacro(ItemType, XdmfInt32); 196 //! Get the Type. One of : XDMF_ITEM_UNIFORM, XDMF_ITEM_COLLECTION, XDMF_ITEM_TREE 197 XdmfGetValueMacro(ItemType, XdmfInt32); 198 //! Get if ItemType evaluates to a Single or Multiple XdmfArray. Collection and tree are multiple. GetIsMultiple()199 XdmfInt32 GetIsMultiple() { return((this->ItemType & XDMF_ITEM_MASK) ? 1: 0); }; 200 //! Set the Function String 201 XdmfSetStringMacro(Function); 202 //! Get the Function String 203 XdmfGetStringMacro(Function); 204 //! Release Large Data 205 XdmfInt32 Release(); 206 XdmfGetValueMacro(ColumnMajor, XdmfInt32); 207 XdmfSetValueMacro(ColumnMajor, XdmfInt32); 208 XdmfGetValueMacro(TransposeInMemory, XdmfInt32); 209 XdmfSetValueMacro(TransposeInMemory, XdmfInt32); 210 211 protected: 212 XdmfInt32 Format; 213 XdmfInt32 DataDescIsMine; 214 XdmfInt32 ArrayIsMine; 215 XdmfInt32 ItemType; 216 XdmfDataDesc *DataDesc; 217 XdmfArray *Array; 218 XdmfValues *Values; 219 XdmfString HeavyDataSetName; 220 XdmfString Function; 221 XdmfInt32 ColumnMajor; 222 XdmfInt32 TransposeInMemory; 223 224 //! Make sure this->Values is correct 225 XdmfInt32 CheckValues(XdmfInt32 Format); 226 XdmfInt32 UpdateInformationUniform(); 227 XdmfInt32 UpdateInformationCollection(); 228 XdmfInt32 UpdateInformationTree(); 229 XdmfInt32 UpdateInformationFunction(); // HyperSlab, Coordinates or Function 230 XdmfInt32 UpdateFunction(); // HyperSlab, Coordinates or Function 231 }; 232 233 } 234 #endif // __XdmfDataItem_h 235