/[escript]/trunk/escript/src/DataAbstract.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataAbstract.cpp

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

revision 2086 by jfenwick, Mon Nov 24 02:38:50 2008 UTC revision 2271 by jfenwick, Mon Feb 16 05:08:29 2009 UTC
# Line 16  Line 16 
16  #include "DataException.h"  #include "DataException.h"
17  #include "DataLazy.h"  #include "DataLazy.h"
18    
19    #include "Data.h"       // So we can update the shared status when things change
20    
21  using namespace std;  using namespace std;
22    
23  namespace escript {  namespace escript {
24    
 /**  
 \brief Returns smart pointer which is managing this object.  
 If one does not exist yet it creates one.  
   
 Note: This is _not_ equivalent to weak_ptr::lock.  
 */  
25  DataAbstract_ptr DataAbstract::getPtr()  DataAbstract_ptr DataAbstract::getPtr()
26  {  {
27    if (_internal_weak_this.expired())    if (_internal_weak_this.expired())
# Line 50  const_DataAbstract_ptr DataAbstract::get Line 46  const_DataAbstract_ptr DataAbstract::get
46    }    }
47  }  }
48    
49    
50    // Warning - this method uses .use_count() which the boost doco labels inefficient.
51    // If this method needs to be called in debug contexts, we may need to do some
52    // timing experiments to determine how inefficient and possibly switch over to
53    // invasive pointers which can answer these questions faster
54    bool DataAbstract::checkNoSharing() const
55    {
56    
57      return !m_lazyshared && (m_owners.size()<2);
58    
59    /*  if (_internal_weak_this.expired())  // there is no shared_ptr for this object yet
60      {
61        return true;
62      }
63      if (shared_from_this().use_count()==2)    // shared_from_this will increase the ref count
64      {                     // which is the reason .unique is no use.
65        return true;
66      }
67    std::cerr << "-<"<<shared_from_this().use_count() << ">-" << endl;
68      return false;*/
69    }
70    
71  bool  bool
72  DataAbstract::isLazy() const  DataAbstract::isLazy() const
73  {  {
# Line 64  DataAbstract::DataAbstract(const Functio Line 82  DataAbstract::DataAbstract(const Functio
82      m_functionSpace(what),      m_functionSpace(what),
83      m_shape(shape),      m_shape(shape),
84      m_novalues(DataTypes::noValues(shape)),      m_novalues(DataTypes::noValues(shape)),
85      m_rank(DataTypes::getRank(shape))      m_rank(DataTypes::getRank(shape)),
86        m_lazyshared(false)
87    
88  {  {
89      m_isempty=isDataEmpty;      m_isempty=isDataEmpty;
# Line 146  DataAbstract::getTagNumber(int dpno) Line 165  DataAbstract::getTagNumber(int dpno)
165      return (0);      return (0);
166  }  }
167    
   
   
 void  
 DataAbstract::copyAll(const boost::python::numeric::array& value)  
 {  
     throw DataException("Error - DataAbstract::copying data from numarray objects is not supported.");  
 }  
168  void  void
169  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const double value)
170  {  {
171      throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");      throw DataException("Error - DataAbstract::copying data from double value to a single data point is not supported.");
172  }  }
173    
174    
175  void  void
176  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const boost::python::numeric::array& value)  DataAbstract::copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value)
177  {  {
178      throw DataException("Error - DataAbstract::copying data from numarray objects to a single data point is not supported.");      throw DataException("Error - DataAbstract::copying data from WrappedArray objects to a single data point is not supported.");
179  }  }
180    
181    
182  void  void
183  DataAbstract::symmetric(DataAbstract* ev)  DataAbstract::symmetric(DataAbstract* ev)
184  {  {
# Line 217  DataAbstract::reorderByReferenceIDs(int Line 232  DataAbstract::reorderByReferenceIDs(int
232  }  }
233    
234    
235  // DataTypes::ValueType&  void DataAbstract::addOwner(Data* d)
236  // DataAbstract::getVector()  {
237  // {    for (size_t i=0;i<m_owners.size();++i)
238  //    throw DataException("Error - DataAbstract:: does not have a DataVector.");    {
239  // }      if (m_owners[i]==d)
240  //      {
241  // const DataTypes::ValueType&          return;
242  // DataAbstract::getVector() const      }
243  // {    }
244  //    throw DataException("Error - DataAbstract:: does not have a DataVector.");    m_owners.push_back(d);
245  // }  // cerr << "Adding " << d << " as an owner of " << this << " now O=" << m_owners.size() << endl;
246      if (m_owners.size()==2)   // Means it used to be 1 so we need to tell people
247      {
248        for (size_t i=0;i<m_owners.size();++i)
249        {
250            m_owners[i]->updateShareStatus(true);
251        }
252      }
253    }
254    
255    void DataAbstract::removeOwner(Data* d)
256    {
257      for (size_t i=0;i<m_owners.size();++i)
258      {
259        if (m_owners[i]==d)
260        {
261            m_owners.erase(m_owners.begin()+i,m_owners.begin()+(i+1));  // remove the element
262            break;
263        }
264      }
265      if (m_owners.size()==1)   // Means it used to be 2 so we need to tell people
266      {
267        m_owners[0]->updateShareStatus(isShared());     // could still be lazy shared
268      }
269    }
270    
271    
272    void DataAbstract::makeLazyShared()
273    {
274        m_lazyshared=true;  // now we need to inform all the owners
275        for (size_t i=0;i<m_owners.size();++i)
276        {
277            m_owners[i]->updateShareStatus(true);
278        }
279    }  
280    
281    
282  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.2086  
changed lines
  Added in v.2271

  ViewVC Help
Powered by ViewVC 1.1.26