Skip to content
  • Mark OLESEN's avatar
    ENH: more consistent single-ownership when swapping fileHandlers · 9711b7f1
    Mark OLESEN authored and Andrew Heather's avatar Andrew Heather committed
    - make fileHandler deletion mechanism more
      transparent by providing a nullptr signature. A nullptr parameter
      is already being used in the argList destructor for shutdown, but that
      relied on an implicit conversion to autoPtr to trigger things.
    
    - improved handling of file handler replacement.
    
      Previously had a very basic check on old vs new handlers using their
      type() values (string comparison!!), which would unfortunately
      prevent proper swapping of the contents.
      Check the actual pointers instead.
    
      As part of the change, treat any empty autoPtr as no-op instead of as
      deletion (which is handled explicitly as nullptr instead).
    
      In addition to making the internal logic simpler, it means that the
      current file handler always changes to a valid state without
      inadvertently removing everything and falling back to creating a new
      default handler (again).
    
      This handling of no-ops also simplifies call code. For example,
    
      <code>
          autoPtr<fileHandler> oldHandler;
          autoPtr<fileHandler> writeHandler;
          word handlerName;
    
          if (arg.readIfPresent("writeHandler", handlerName))
          {
              writeHandler = fileOperation::New(handlerName);
          }
    
          oldHandler = fileHandler(std::move(writeHandler));
    
          ... do something
    
          writeHandler = fileHandler(std::move(oldHandler));
      </code>
    
      If the "writeHandler" is not specified, each call is a no-op.
      If it is specified, the handlers are swapped out each time.
    
    - the management of the fileHandler communicators is now encapsulated
      privately (managedComm_) with the final layer being responsible for
      cleaning up after itself. This makes delegation/inheritance clearer
      and avoids the risk of freeing an MPI communicator twice.
    
    STYLE: uniformFile static check relocated to fileOperation layer
    9711b7f1