/[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 123 by jgs, Fri Jul 8 04:08:13 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 146  class DataTagged : public DataAbstract { Line 166  class DataTagged : public DataAbstract {
166       \param dataPointNo - Input - data-point number.       \param dataPointNo - Input - data-point number.
167     */     */
168    virtual    virtual
169    DataArrayView::ValueType::size_type    ValueType::size_type
170    getPointOffset(int sampleNo,    getPointOffset(int sampleNo,
171                   int dataPointNo) const;                   int dataPointNo) const;
172    
# Line 155  class DataTagged : public DataAbstract { Line 175  class DataTagged : public DataAbstract {
175       addTaggedValues       addTaggedValues
176    
177       Description:       Description:
178       Add the given tags and values to this DataTagged object.       Add the given tags and values to this DataTagged object, by repeatedly
179         using addTaggedValue for each given tag/value pair.
180       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
181       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
182                     then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
183                     it contains one value all tags will be assigned the same value.                        it contains one value all tags will be assigned the same value.
184                     Otherwise if there is a mismatch between the number of tags and                        Otherwise if there is a mismatch between the number of tags and
185                     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.  
186    */    */
187    void    void
188    addTaggedValues(const TagListType& tagKeys,    addTaggedValues(const TagListType& tagKeys,
# Line 175  class DataTagged : public DataAbstract { Line 193  class DataTagged : public DataAbstract {
193       addTaggedValue       addTaggedValue
194    
195       Description:       Description:
196       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
197         a value associated with it, setTaggedValue will be used to update this value.
198       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
199       \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.  
200    */    */
201    void    void
202    addTaggedValue(int tagKey,    addTaggedValue(int tagKey,
# Line 191  class DataTagged : public DataAbstract { Line 207  class DataTagged : public DataAbstract {
207       setTaggedValues       setTaggedValues
208    
209       Description:       Description:
210       Assign the given values to the tags listed.       Set the given tags to the given values in this DataTagged object, by repeatedly
211         using setTaggedValue for each given tag/value pair.
212       \param tagKeys - Input - A vector of integer keys.       \param tagKeys - Input - A vector of integer keys.
213       \param values - Input - A vector of DataArrayViews. If this is empty       \param values - Input - A vector of DataArrayViews. If this is empty
214                        then all given tags will be assigned a value of zero. If                        then all given tags will be assigned a value of zero. If
215                        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.
216                        Otherwise if there is a mismatch between the number of keys and                        Otherwise if there is a mismatch between the number of keys and
217                        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.  
218    */    */
219    void    void
220    setTaggedValues(const TagListType& tagKeys,    setTaggedValues(const TagListType& tagKeys,
# Line 209  class DataTagged : public DataAbstract { Line 225  class DataTagged : public DataAbstract {
225       setTaggedValue       setTaggedValue
226    
227       Description:       Description:
228       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
229         associated with it, addTaggedValue will be used to add this tag/value pair.
230       \param tagKey - Input - Integer key.       \param tagKey - Input - Integer key.
231       \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.  
232    */    */
233    virtual    virtual
234    void    void
# Line 280  class DataTagged : public DataAbstract { Line 296  class DataTagged : public DataAbstract {
296    DataArrayView&    DataArrayView&
297    getDefaultValue();    getDefaultValue();
298    
   /**  
      \brief  
      getDefaultValue  
   
      Description:  
      Return the default value, const version.  
   */  
299    const DataArrayView&    const DataArrayView&
300    getDefaultValue() const;    getDefaultValue() const;
301    
# Line 340  class DataTagged : public DataAbstract { Line 349  class DataTagged : public DataAbstract {
349    void    void
350    reshapeDataPoint(const DataArrayView::ShapeType& shape);    reshapeDataPoint(const DataArrayView::ShapeType& shape);
351    
352      /**
353        \brief
354        Archive the underlying data values to the file referenced
355        by ofstream. A count of the number of values expected to be written
356        is provided as a cross-check.
357    
358        The return value indicates success (0) or otherwise (1).
359      */
360      int
361      archiveData(std::ofstream& archiveFile,
362                  const DataArrayView::ValueType::size_type noValues) const;
363    
364      /**
365        \brief
366        Extract the number of values specified by noValues from the file
367        referenced by ifstream to the underlying data structure.
368    
369        The return value indicates success (0) or otherwise (1).
370      */
371      int
372      extractData(std::ifstream& archiveFile,
373                  const DataArrayView::ValueType::size_type noValues);
374    
375   protected:   protected:
376    
377   private:   private:
# Line 349  class DataTagged : public DataAbstract { Line 381  class DataTagged : public DataAbstract {
381    DataMapType m_offsetLookup;    DataMapType m_offsetLookup;
382    
383    //    //
   // The actual data  
   DataArrayView::ValueType m_data;  
   
   //  
384    // the default value offset    // the default value offset
385    static const int m_defaultValueOffset = 0;    static const int m_defaultValueOffset = 0;
386    
387      //
388      // The actual data
389      ValueType m_data;
390    
391  };  };
392    
393  inline  inline
# Line 370  inline Line 402  inline
402  DataArrayView&  DataArrayView&
403  DataTagged::getDefaultValue()  DataTagged::getDefaultValue()
404  {  {
   //  
405    // The default value is always the first value.    // The default value is always the first value.
406    return getPointDataView();    return getPointDataView();
407  }  }
# Line 379  inline Line 410  inline
410  const DataArrayView&  const DataArrayView&
411  DataTagged::getDefaultValue() const  DataTagged::getDefaultValue() const
412  {  {
   //  
413    // The default value is always the first value.    // The default value is always the first value.
414    return getPointDataView();    return getPointDataView();
415  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26