/[escript]/branches/arrayview_from_1695_trunk/escript/src/DataTagged.h
ViewVC logotype

Diff of /branches/arrayview_from_1695_trunk/escript/src/DataTagged.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/esys2/escript/src/Data/DataTagged.h revision 97 by jgs, Tue Dec 14 05:39:33 2004 UTC trunk/escript/src/DataTagged.h revision 480 by jgs, Wed Feb 1 05:15:12 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2  /*  
3    /*
4   ******************************************************************************   ******************************************************************************
5   *                                                                            *   *                                                                            *
6   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *
# Line 12  Line 13 
13   *                                                                            *   *                                                                            *
14   ******************************************************************************   ******************************************************************************
15  */  */
16                                                                              
17  #if !defined escript_DataTagged_20040615_H  #if !defined escript_DataTagged_20040615_H
18  #define escript_DataTagged_20040615_H  #define escript_DataTagged_20040615_H
19    
20  #include "escript/Data/DataAbstract.h"  #include "DataAbstract.h"
21  #include "escript/Data/DataArray.h"  #include "DataArrayView.h"
 #include "escript/Data/DataArrayView.h"  
22    
23  #include <vector>  #include <vector>
24  #include <map>  #include <map>
# Line 44  class DataTagged : public DataAbstract { Line 44  class DataTagged : public DataAbstract {
44    
45   public:   public:
46    
47    typedef std::vector<int> TagListType;    //
48      // Types for the lists of tags and values
49      typedef std::vector<int>           TagListType;
50    typedef std::vector<DataArrayView> ValueListType;    typedef std::vector<DataArrayView> ValueListType;
51      typedef DataArrayView::ValueType   ValueType;
52    
53    //    //
54    // Map type, maps the key to an array offset.    // Map from the tag to an offset the the data array.
55    typedef std::map<int, int> DataMapType;    typedef std::map<int, int> DataMapType;
56    
57    /**    /**
# Line 85  class DataTagged : public DataAbstract { Line 88  class DataTagged : public DataAbstract {
88    
89    /**    /**
90       \brief       \brief
91         Alternative constructor for DataTagged objects.
92    
93         Description:
94         Alternative Constructor for DataTagged objects.
95         \param what - Input - A description of what this data object represents.
96         \param shape - Input - the shape of each data-point.
97         \param tags - Input - array of tags, one for each sample number
98         \param data - the data values for each data-point.
99      */
100      DataTagged(const FunctionSpace& what,
101                 const DataArrayView::ShapeType &shape,
102                 const int tags[],
103                 const ValueType &data);
104    
105      /**
106         \brief
107       Slice constructor for DataTagged.       Slice constructor for DataTagged.
108    
109       Description:       Description:
# Line 135  class DataTagged : public DataAbstract { Line 154  class DataTagged : public DataAbstract {
154    
155    /**    /**
156       \brief       \brief
157         Return the tag number associated with the given data-point number.
158      */
159      virtual
160      int
161      getTagNumber(int dpno);
162    
163      /**
164         \brief
165       getPointOffset       getPointOffset
166    
167       Description:       Description:
# Line 146  class DataTagged : public DataAbstract { Line 173  class DataTagged : public DataAbstract {
173       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
174     */     */
175    virtual    virtual
176    DataArrayView::ValueType::size_type    ValueType::size_type
177    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
178                   int dataPointNo) const;                   int dataPointNo) const;
179    
# Line 155  class DataTagged : public DataAbstract { Line 182  class DataTagged : public DataAbstract {
182       addTaggedValues       addTaggedValues
183    
184       Description:       Description:
185       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object, by repeatedly
186         using addTaggedValue for each given tag/value pair.
187       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
188       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
189                     then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
190                     it contains one value all tags will be assigned the same value.                        it contains one value all tags will be assigned the same value.
191                     Otherwise if there is a mismatch between the number of tags and                        Otherwise if there is a mismatch between the number of tags and
192                     the number of values an exception will be generated.                        the number of values an exception will be generated.
      NB: If a tag given here already exists in this object, this attempt to add the given  
      value will have no effect. setTaggedValues is more versatile and should be  
      used in most cases in preference to addTaggedValues.  
193    */    */
194    void    void
195    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 200  class DataTagged : public DataAbstract {
200       addTaggedValue       addTaggedValue
201    
202       Description:       Description:
203       Add a single tag and value to this DataTagged object.       Add a single tag and value to this DataTagged object. If this tag already has
204         a value associated with it, setTaggedValue will be used to update this value.
205       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
206       \param value - Input - DataArrayView.       \param value - Input - Single DataArrayView value to be assigned to the tag.
      NB: If this tag already exists in this object, this attempt to add the given  
      value will have no effect. setTaggedValue is more versatile and should be  
      used in most cases in preference to addTaggedValue.  
207    */    */
208    void    void
209    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  class DataTagged : public DataAbstract { Line 214  class DataTagged : public DataAbstract {
214       setTaggedValues       setTaggedValues
215    
216       Description:       Description:
217       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object, by repeatedly
218         using setTaggedValue for each given tag/value pair.
219       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
220       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
221                        then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
222                        it contains one value all tag values will be assigned the same value.                        it contains one value all tag values will be assigned the same value.
223                        Otherwise if there is a mismatch between the number of keys and                        Otherwise if there is a mismatch between the number of keys and
224                        the number of values an exception will be generated.                        the number of values an exception will be generated.
      NB: If a given tag does not yet exist in this DataTagged object, it will be added.  
225    */    */
226    void    void
227    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 209  class DataTagged : public DataAbstract { Line 232  class DataTagged : public DataAbstract {
232       setTaggedValue       setTaggedValue
233    
234       Description:       Description:
235       Assign the given value to the given tag.       Assign the given value to the given tag. If this tag does not already have a value
236         associated with it, addTaggedValue will be used to add this tag/value pair.
237       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
238       \param value - Input - Single DataArrayView value to be assigned to the tag.       \param value - Input - Single DataArrayView value to be assigned to the tag.
      NB: If the given tag does not yet exist in this DataTagged object, it will be added.  
239    */    */
240    virtual    virtual
241    void    void
# Line 280  class DataTagged : public DataAbstract { Line 303  class DataTagged : public DataAbstract {
303    DataArrayView&    DataArrayView&
304    getDefaultValue();    getDefaultValue();
305    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
306    const DataArrayView&    const DataArrayView&
307    getDefaultValue() const;    getDefaultValue() const;
308    
# Line 340  class DataTagged : public DataAbstract { Line 356  class DataTagged : public DataAbstract {
356    void    void
357    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
358    
359      /**
360        \brief
361        Archive the underlying data values to the file referenced
362        by ofstream. A count of the number of values expected to be written
363        is provided as a cross-check.
364    
365        The return value indicates success (0) or otherwise (1).
366      */
367      int
368      archiveData(std::ofstream& archiveFile,
369                  const DataArrayView::ValueType::size_type noValues) const;
370    
371      /**
372        \brief
373        Extract the number of values specified by noValues from the file
374        referenced by ifstream to the underlying data structure.
375    
376        The return value indicates success (0) or otherwise (1).
377      */
378      int
379      extractData(std::ifstream& archiveFile,
380                  const DataArrayView::ValueType::size_type noValues);
381    
382   protected:   protected:
383    
384   private:   private:
# Line 349  class DataTagged : public DataAbstract { Line 388  class DataTagged : public DataAbstract {
388    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
389    
390    //    //
   // The actual data  
   DataArrayView::ValueType m_data;  
   
   //  
391    // the default value offset    // the default value offset
392    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
393    
394      //
395      // The actual data
396      ValueType m_data;
397    
398  };  };
399    
400  inline  inline
# Line 370  inline Line 409  inline
409  DataArrayView&  DataArrayView&
410  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
411  {  {
   //  
412    // The default value is always the first value.    // The default value is always the first value.
413    return getPointDataView();    return getPointDataView();
414  }  }
# Line 379  inline Line 417  inline
417  const DataArrayView&  const DataArrayView&
418  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
419  {  {
   //  
420    // The default value is always the first value.    // The default value is always the first value.
421    return getPointDataView();    return getPointDataView();
422  }  }

Legend:
Removed from v.97  
changed lines
  Added in v.480

  ViewVC Help
Powered by ViewVC 1.1.26