1 /***********************************************************************/ 2 /* Open Visualization Data Explorer */ 3 /* (C) Copyright IBM Corp. 1989,1999 */ 4 /* ALL RIGHTS RESERVED */ 5 /* This code licensed under the */ 6 /* "IBM PUBLIC LICENSE - Open Visualization Data Explorer" */ 7 /***********************************************************************/ 8 9 #include <dxconfig.h> 10 #include "../base/defines.h" 11 12 13 #ifndef _DXTensor_h 14 #define _DXTensor_h 15 16 17 #include "Base.h" 18 19 20 boolean IsTensor(const char *s, int& index); 21 boolean IsVector(const char *s, int& index, int& tuple); 22 23 24 // 25 // Class name definition: 26 // 27 #define ClassDXTensor "DXTensor" 28 29 // 30 // DXTensor class definition: 31 // 32 class DXTensor : public Base 33 { 34 private: 35 // 36 // Private member data: 37 // 38 double *scalars; // List of scalar values 39 DXTensor **tensors; // List of vector values 40 int dimensions; // Number of dimensions in the vector 41 char *dim_sizes; // Size of each dimension. 42 char *strval; // String representing vector value. 43 char *formatTensor(char *s, int& index); 44 45 protected: 46 // 47 // Protected member data: 48 // 49 50 51 52 53 public: 54 // 55 // Constructor: 56 // DXTensor()57 DXTensor(){ scalars = NUL(double*); 58 tensors = NUL(DXTensor**); 59 dimensions = 0; 60 dim_sizes = NUL(char*); 61 strval = NUL(char*); } 62 63 // 64 // Destructor: 65 // 66 ~DXTensor(); 67 68 // 69 // Set the vector value from a null terminated string. 70 // 71 void printValue(); 72 73 74 // 75 // Set the vector value from a null terminated string. 76 // 77 boolean setValue(const char* string); 78 boolean setValue(const char *s, int& index); 79 80 // 81 // Put the vector value in a null terminated string. 82 // 83 const char *getValueString(); 84 85 // 86 // Return the number of dimensions in this tensor. 87 // getDimensions()88 int getDimensions() { return dimensions; } 89 90 // 91 // Get the number of items in the given dimension. 92 // Dimensions are indexed from 1. 93 // 94 int getDimensionSize(int dim); 95 96 // 97 // Return the value of the i'th component of a vector. 98 // indexing is one based. 99 // getVectorComponentValue(int component)100 double getVectorComponentValue(int component) 101 { 102 ASSERT(this->getDimensions() == 1); 103 ASSERT(this->dim_sizes[0] >= component); 104 return this->scalars[component-1]; 105 } getVectorComponentCount()106 int getVectorComponentCount() 107 { 108 return this->getDimensionSize(1); 109 } 110 // 111 // Set the value of the i'th component of a vector. 112 // indexing is one based. 113 // 114 boolean setVectorComponentValue(int component, double val); 115 116 // 117 // Make a copy of this vector. 118 // 119 DXTensor *dup(); 120 121 // 122 // Returns a pointer to the class name. 123 // getClassName()124 virtual const char* getClassName() 125 { 126 return ClassDXTensor; 127 } 128 }; 129 130 131 #endif // _DXTensor_h 132