/[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

revision 102 by jgs, Wed Dec 15 07:08:39 2004 UTC revision 149 by jgs, Thu Sep 1 03:31:39 2005 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    
# Line 44  class DataTagged : public DataAbstract { Line 45  class DataTagged : public DataAbstract {
45    
46   public:   public:
47    
48    typedef std::vector<int> TagListType;    //
49      // Types for the lists of tags and values
50      typedef std::vector<int>           TagListType;
51    typedef std::vector<DataArrayView> ValueListType;    typedef std::vector<DataArrayView> ValueListType;
52      typedef DataArrayView::ValueType   ValueType;
53    
54    //    //
55    // Map type, maps the key to an array offset.    // Map from the tag to an offset the the data array.
56    typedef std::map<int, int> DataMapType;    typedef std::map<int, int> DataMapType;
57    
58    /**    /**
# Line 85  class DataTagged : public DataAbstract { Line 89  class DataTagged : public DataAbstract {
89    
90    /**    /**
91       \brief       \brief
92         Alternative constructor for DataTagged objects.
93    
94         Description:
95         Alternative Constructor for DataTagged objects.
96         \param what - Input - A description of what this data object represents.
97         \param shape - Input - the shape of each data-point.
98         \param tags - Input - array of tags, one for each sample number
99         \param data - the data values for each data-point.
100      */
101      DataTagged(const FunctionSpace& what,
102                 const DataArrayView::ShapeType &shape,
103                 const int tags[],
104                 const ValueType &data);
105    
106      /**
107         \brief
108       Slice constructor for DataTagged.       Slice constructor for DataTagged.
109    
110       Description:       Description:
# Line 135  class DataTagged : public DataAbstract { Line 155  class DataTagged : public DataAbstract {
155    
156    /**    /**
157       \brief       \brief
158         Return the tag number associated with the given data-point number.
159      */
160      virtual
161      int
162      getTagNumber(int dpno);
163    
164      /**
165         \brief
166       getPointOffset       getPointOffset
167    
168       Description:       Description:
# Line 146  class DataTagged : public DataAbstract { Line 174  class DataTagged : public DataAbstract {
174       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
175     */     */
176    virtual    virtual
177    DataArrayView::ValueType::size_type    ValueType::size_type
178    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
179                   int dataPointNo) const;                   int dataPointNo) const;
180    
# Line 155  class DataTagged : public DataAbstract { Line 183  class DataTagged : public DataAbstract {
183       addTaggedValues       addTaggedValues
184    
185       Description:       Description:
186       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object, by repeatedly
187         using addTaggedValue for each given tag/value pair.
188       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
189       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
190                     then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
191                     it contains one value all tags will be assigned the same value.                        it contains one value all tags will be assigned the same value.
192                     Otherwise if there is a mismatch between the number of tags and                        Otherwise if there is a mismatch between the number of tags and
193                     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.  
194    */    */
195    void    void
196    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 201  class DataTagged : public DataAbstract {
201       addTaggedValue       addTaggedValue
202    
203       Description:       Description:
204       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
205         a value associated with it, setTaggedValue will be used to update this value.
206       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
207       \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.  
208    */    */
209    void    void
210    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  class DataTagged : public DataAbstract { Line 215  class DataTagged : public DataAbstract {
215       setTaggedValues       setTaggedValues
216    
217       Description:       Description:
218       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object, by repeatedly
219         using setTaggedValue for each given tag/value pair.
220       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
221       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
222                        then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
223                        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.
224                        Otherwise if there is a mismatch between the number of keys and                        Otherwise if there is a mismatch between the number of keys and
225                        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.  
226    */    */
227    void    void
228    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 209  class DataTagged : public DataAbstract { Line 233  class DataTagged : public DataAbstract {
233       setTaggedValue       setTaggedValue
234    
235       Description:       Description:
236       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
237         associated with it, addTaggedValue will be used to add this tag/value pair.
238       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
239       \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.  
240    */    */
241    virtual    virtual
242    void    void
# Line 280  class DataTagged : public DataAbstract { Line 304  class DataTagged : public DataAbstract {
304    DataArrayView&    DataArrayView&
305    getDefaultValue();    getDefaultValue();
306    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
307    const DataArrayView&    const DataArrayView&
308    getDefaultValue() const;    getDefaultValue() const;
309    
# Line 340  class DataTagged : public DataAbstract { Line 357  class DataTagged : public DataAbstract {
357    void    void
358    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
359    
360      /**
361        \brief
362        Archive the underlying data values to the file referenced
363        by ofstream. A count of the number of values expected to be written
364        is provided as a cross-check.
365    
366        The return value indicates success (0) or otherwise (1).
367      */
368      int
369      archiveData(std::ofstream& archiveFile,
370                  const DataArrayView::ValueType::size_type noValues) const;
371    
372      /**
373        \brief
374        Extract the number of values specified by noValues from the file
375        referenced by ifstream to the underlying data structure.
376    
377        The return value indicates success (0) or otherwise (1).
378      */
379      int
380      extractData(std::ifstream& archiveFile,
381                  const DataArrayView::ValueType::size_type noValues);
382    
383   protected:   protected:
384    
385   private:   private:
# Line 349  class DataTagged : public DataAbstract { Line 389  class DataTagged : public DataAbstract {
389    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
390    
391    //    //
   // The actual data  
   DataArrayView::ValueType m_data;  
   
   //  
392    // the default value offset    // the default value offset
393    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
394    
395      //
396      // The actual data
397      ValueType m_data;
398    
399  };  };
400    
401  inline  inline
# Line 370  inline Line 410  inline
410  DataArrayView&  DataArrayView&
411  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
412  {  {
   //  
413    // The default value is always the first value.    // The default value is always the first value.
414    return getPointDataView();    return getPointDataView();
415  }  }
# Line 379  inline Line 418  inline
418  const DataArrayView&  const DataArrayView&
419  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
420  {  {
   //  
421    // The default value is always the first value.    // The default value is always the first value.
422    return getPointDataView();    return getPointDataView();
423  }  }

Legend:
Removed from v.102  
changed lines
  Added in v.149

  ViewVC Help
Powered by ViewVC 1.1.26