assignment operator for folder class

Jun 10, 2010 at 2:53 PM

Is there a plan to implement an assignment operator for the folder class? In my code I need to find the folder inside the PST and default assignment operator causes the compiler error. Below is my method with the line causing the error.

 folder CPstLib::getFolder(pst *pstData, vector<wstring>pathToFolder) {
  folder ret = pstData->open_root_folder();
  for(vector<wstring>::const_iterator it = pathToFolder.begin(); it != pathToFolder.end(); ++it)
   folder tmp = folder::folder(ret);

   //the line below causes compiler error: Error 1 error C2248: 'pstsdk::property_bag::operator =' : cannot access private member declared in class 'pstsdk::property_bag' c:\Projects\pstsdk\pstsdk\pst\folder.h 298 PstLib

   ret = tmp.open_sub_folder(*it);  
  return ret;

Jun 10, 2010 at 3:33 PM

This is intentional. Generally objects at the lower layers are not assignable, but they are copy constructible. The reason is that the semantics of assignment are ambiguous.  If I assign node a to node b, does that mean I just changed the contents of node a on disk to be equal to the contents of node b, or that i just changed the in memory object node a to refer to node b as well (creating two node b's in memory)? Copy construction is unambiguous, so that is implemented. This bubbles up through the SDK. 

I'm not opposed to revisiting this design decision if a design comes up that makes sense; but generally it's pretty common for in memory representations of disk resources to be non-assignable, unless assignment is implemented as a quasi-write operation on that resource.

Jun 10, 2010 at 3:39 PM

Is there a way to get around the lack of  assignment operator for foldes and messages? It seems to me that without it them some functionality (like the task I am trying to solve above) will be very difficult if not impossible to implement.

Jun 10, 2010 at 3:44 PM
You could take advantage of the fact that the objects are copyable, or just use pointers to the objects (since the pointers will be copyable). There are a lot of techniques you could use. In your example, the first thing that comes to mind actually is writing it as a tail-recursive function.
Jun 11, 2010 at 2:40 PM

Perhaps the lack of assignment operator makes sense from architectural perspective, but it imposes limitations on coding techniques available and in some instances makes the code difficult to read.
The constructs like this (which I am pretty sure will be needed often) will not work:

vector<folder> foldersList;
folder root = pstData->open_root_folder();
folders.push_back(root); //fails because STL folder needs assignment operator

working with the pointer makes code unwieldy and in some case will not work because the pointers have to point to real objects which have to be assigned somehow. Consider my case (I don’t like using tail recursion since most of the compilers will convert it to iterator anyway). I just need to find a folder based on its location within the folder three.

folder CPstLib::getFolder(const pst *pstData vector<wstring>path) {
      folder root = pstData->open_root_folder();
      folder *ret = &root;
      for(vector<wstring>::const_iterator it = path.begin(); it != path.end(); ++it)
            folder *tmp = ret;
            folder current = tmp->open_sub_folder(*it);
            ret = &current;               
      folder returnedFolder = folder::folder(*ret); // will not work because “current” is out of scope          
      return returnedFolder;