degate  0.1.2
Public Member Functions | Static Protected Member Functions
degate::DeepCopyable Class Reference

DeepCopyable is a type for cloneable objects (deep-copyable). More...

#include <DeepCopyable.h>

Inheritance diagram for degate::DeepCopyable:
Inheritance graph
[legend]

List of all members.

Public Member Functions

virtual DeepCopyable_shptr cloneShallow () const =0
 Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.
virtual DeepCopyable_shptr cloneDeep (oldnew_t *oldnew) const
 Return a deep-copy of this object, i.e.

Static Protected Member Functions

static bool cloneOnce (const c_DeepCopyable_shptr &o, oldnew_t *oldnew)
 Store o->cloneShallow() in oldnew[o], unless there already exists such a clone.

Detailed Description

DeepCopyable is a type for cloneable objects (deep-copyable).

You can think of an object hierarchy as a graph. To make a deep-copy possible, all leafs of the graph must implement the DeepCopyable interface, and the inner nodes must implement the DeepCopyableBase interface. Then, it is possible to recursively visit all nodes in the graph by calling cloneDeep().

The oldnew mapping is used to ensure that each object in the object hierarchy is copied only once, even if there are multiple paths to the object in the hierarchy. This is achieved by searching for an existing clone in the map before cloning the respective object.

Definition at line 58 of file DeepCopyable.h.


Member Function Documentation

Return a deep-copy of this object, i.e.

with all DeepCopyable members deep-copied themselves.

Use oldnew to avoid cloning objects multiple times.

Definition at line 27 of file DeepCopyable.cc.

References degate::DeepCopyableBase::cloneDeepInto(), and cloneOnce().

                                                                 {
  auto _this = shared_from_this();
  if (cloneOnce(_this, oldnew)) {
    cloneDeepInto((*oldnew)[_this], oldnew);
  }
  return (*oldnew)[_this];
}

Here is the call graph for this function:

bool degate::DeepCopyable::cloneOnce ( const c_DeepCopyable_shptr o,
oldnew_t oldnew 
) [static, protected]

Store o->cloneShallow() in oldnew[o], unless there already exists such a clone.

This should be used as convenience function in cloneDeep() implementations.

Definition at line 35 of file DeepCopyable.cc.

Referenced by cloneDeep().

                                                                                                                      {
  assert(o.get() != 0);
  
  std::map<c_DeepCopyable_shptr, DeepCopyable_shptr> &oldnew = *__oldnew;
  if (oldnew.count(o) > 0) {
    return false;
  }
  
  DeepCopyable_shptr clone = o->cloneShallow();
  oldnew[o] = clone;
  return true;
}

Here is the caller graph for this function:

virtual DeepCopyable_shptr degate::DeepCopyable::cloneShallow ( ) const [pure virtual]

Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.

set to 0-pointer).

Implemented in degate::LogicModel, degate::Project, degate::GateTemplate, degate::Layer, degate::Annotation, degate::Net, degate::Module, degate::Gate, degate::GatePort, degate::Via, degate::GateTemplatePort, degate::GateLibrary, degate::EMarker, and degate::Wire.


The documentation for this class was generated from the following files: