/[escript]/branches/windows_from_1431_trunk/escript/src/FunctionSpace.h
ViewVC logotype

Diff of /branches/windows_from_1431_trunk/escript/src/FunctionSpace.h

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

revision 1433 by trankine, Wed Feb 27 10:02:34 2008 UTC revision 1434 by trankine, Wed Feb 27 10:50:55 2008 UTC
# Line 22  Line 22 
22    
23  #include <string>  #include <string>
24    
25    // This stops the friend declaration below from looking like a
26    // declaration of escript::FunctionSpaceTestCase.
27    
28  class FunctionSpaceTestCase;  class FunctionSpaceTestCase;
29    
30  namespace escript {  namespace escript {
# Line 135  class FunctionSpace { Line 138  class FunctionSpace {
138    /**    /**
139     \brief     \brief
140     Return a text description of the function space.     Return a text description of the function space.
141       NOTE: In the python interface, the reference return value policy is
142       copy const reference. This mens that if the python string value
143       is assigned to a python variable, it's value (python) value will not
144       change, even if operator=() changes this Function space object.
145       Consequently, it is possible for python to keep a wrong value for this
146       string!
147       Worse still is that operator=() is exposed to python in escriptcpp.cpp.
148    */    */
149    ESCRIPT_DLL_API    ESCRIPT_DLL_API
150    const std::string &    const std::string &
# Line 265  class FunctionSpace { Line 275  class FunctionSpace {
275     Assignment operator.     Assignment operator.
276     NOTE: Assignment copies the domain object pointer     NOTE: Assignment copies the domain object pointer
277     as this object is managed externally to this class.     as this object is managed externally to this class.
278     NOTE Also, breaks the non-mutability of FunctionSpace     Also, breaks the non-mutability of FunctionSpace
279     assumed by toString(). Allowing this would also have     assumed by toString().
    unknown effects at the python level, and could  
    leave python with an incorrect view of the object.  
280    */    */
281    // yes, yes I know, but the test case is in another    // yes, yes I know, but the test case is in another
282    // linkage unit external to the dll.    // linkage unit external to the dll.
283    // This IS supposed to be temporary.    // This IS supposed to be a temporary fix until a more
284      // robust solution is implemented.
285    ESCRIPT_DLL_API    ESCRIPT_DLL_API
286    FunctionSpace&    FunctionSpace&
287    operator=(const FunctionSpace& other);    operator=(const FunctionSpace& other);
# Line 291  class FunctionSpace { Line 300  class FunctionSpace {
300    
301    //    //
302    // return value of toString.    // return value of toString.
303    // made mutable for lazy initialisation in 1st call to toString.    // Made mutable for recalculation by calls to toString.
304    // So, this is conceptually immutable, meaning it expects the FunctionSpace    // This is supposed to be conceptually immutable,
305    // object to be immutable.    // and the mutable declaration is intended to admit lazy init. in the
306      // 1st call to toString()
307      // Unfortunately, the existance of operator=() breaks
308      // the imutability of FunctionSpace, so the current toString()
309      // implementation is in fact an abuse of "mutable".
310      // So why not just return a std::strin & do away with this class member?
311      //
312      // 1. even if an anonymous copy of the value is returned instead of a const
313      //    reference, that value can find it's way into another DLL, especially
314      //    in this environment.
315      // 2. This is especially true of exceptions that are fed said anaonymous
316      //    copy as the retun value of a function into the argument of the
317      //    exception constructor that expects a const reference.
318      // 3. What happens is that the exception object is left holding
319      //    a reference to an onject that is going to get creamed
320      //    during stack unwind.
321      // 4. returning a class value from a stack local is frowned upon anyway,
322      //    this is just one reason not to do it.
323      // 5. There are a number of patters, all well known to C++ programmers
324      //    for avoiding the practice.
325    
326    mutable std::string type_str;    mutable std::string type_str;
327    
328  };  };

Legend:
Removed from v.1433  
changed lines
  Added in v.1434

  ViewVC Help
Powered by ViewVC 1.1.26