degate  0.1.2
Public Types | Public Member Functions | Protected Member Functions | Private Attributes | Friends
degate::Net Class Reference

The net class represents an electrical potential that is shared between electrically adjacent objects. More...

#include <Net.h>

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

List of all members.

Public Types

typedef std::set< object_id_t >
::iterator 
connection_iterator
typedef std::set< object_id_t >
::iterator 
iterator
typedef std::set< object_id_t >
::const_iterator 
const_iterator

Public Member Functions

 Net ()
 Construct a new net.
virtual ~Net ()
 Destroy a net.
virtual connection_iterator begin ()
 Get an iterator to iterate over all objects that are electrically connected with this net.
virtual connection_iterator end ()
 Get an end marker.
virtual unsigned int size () const
 Get the number of objects that are connected with this net.
const std::string get_descriptive_identifier () const
 Get a human readable description for the object.
DeepCopyable_shptr cloneShallow () const
 Return a copy of this object, but with all references to other DeepCopyables cleared (e.g.
void cloneDeepInto (DeepCopyable_shptr destination, oldnew_t *oldnew) const
 Deep-copy all members to destination.

Protected Member Functions

virtual void add_object (ConnectedLogicModelObject_shptr o)
 Add an object of type ConnectedLogicModelObject to the net.
virtual void add_object (object_id_t oid)
 Add an object to the net.
virtual void remove_object (ConnectedLogicModelObject_shptr o)
 Remove an object from a net.
virtual void remove_object (object_id_t o)
 Remove object.

Private Attributes

std::set< object_id_tconnections

Friends

class ConnectedLogicModelObject

Detailed Description

The net class represents an electrical potential that is shared between electrically adjacent objects.

Why do methods in class Net work with object ID instead of shared pointers? There is an automatism. A ConnectedLogicModelObject adds itself to a net, if you set the net for the ConnectedLogicModelObject. And it removes itself from a Net object, if it's destructor is called. The problem is, that the ConnectedLogicModelObject itself only has a this pointer. An object can't have a shared pointer to itself. One could work with normal pointers, but this would somehow circumvent shared pointer approach in libdegate. So we use loosely coupled object IDs.

See also:
ConnectedLogicModelObject::set_net()
ConnectedLogicModelObject::remove_net()

Definition at line 53 of file Net.h.


Member Typedef Documentation

Definition at line 101 of file Net.h.

Definition at line 103 of file Net.h.

Definition at line 102 of file Net.h.


Constructor & Destructor Documentation

Net::Net ( )

Construct a new net.

Definition at line 33 of file Net.cc.

         {
}
Net::~Net ( ) [virtual]

Destroy a net.

See also:
LogicModel::remove_net()

Definition at line 36 of file Net.cc.

          {
}

Member Function Documentation

void Net::add_object ( ConnectedLogicModelObject_shptr  o) [protected, virtual]

Add an object of type ConnectedLogicModelObject to the net.

It is silently ignored, if the object is already referenced from the net.

Exceptions:
InvalidObjectIDExceptionThis exception is thrown if the object has an invalid object ID.

Definition at line 86 of file Net.cc.

                                                      {
  add_object(o->get_object_id());
}
void Net::add_object ( object_id_t  oid) [protected, virtual]

Add an object to the net.

See also:
add_object()

Definition at line 78 of file Net.cc.

References connections.

                                    {
  if(oid == 0)
    throw InvalidObjectIDException("The object that has to be "
                                   "added to the net has no object ID.");
  else
    connections.insert(oid);
}

Get an iterator to iterate over all objects that are electrically connected with this net.

Be careful with iterator invalidation!

Definition at line 50 of file Net.cc.

References connections.

                                  {
  return connections.begin();
}
void Net::cloneDeepInto ( DeepCopyable_shptr  destination,
oldnew_t oldnew 
) const [virtual]

Deep-copy all members to destination.

Todo:
Find out whether the default assignment operator can be used to simplify implementations of this method.

Reimplemented from degate::LogicModelObjectBase.

Definition at line 44 of file Net.cc.

References connections.

                                                                       {
  auto clone = std::dynamic_pointer_cast<Net>(dest);
  clone->connections = connections;
  LogicModelObjectBase::cloneDeepInto(dest, oldnew);
}

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

set to 0-pointer).

Implements degate::DeepCopyable.

Definition at line 39 of file Net.cc.

                                           {
  auto clone = std::make_shared<Net>();
  return clone;
}

Get an end marker.

Definition at line 54 of file Net.cc.

References connections.

                                {
  return connections.end();
}
const std::string Net::get_descriptive_identifier ( ) const [virtual]

Get a human readable description for the object.

Reimplemented from degate::LogicModelObjectBase.

Definition at line 96 of file Net.cc.

References degate::LogicModelObjectBase::get_object_id().

                                                      {
  boost::format fmter("Net %1%");
  fmter % get_object_id();;
  return fmter.str();
}

Here is the call graph for this function:

void Net::remove_object ( ConnectedLogicModelObject_shptr  o) [protected, virtual]

Remove an object from a net.

Exceptions:
CollectionLookupExceptionIndicates that the object is not referenced from the net.
InvalidObjectIDExceptionAs in add_object().
See also:
add_object()

Definition at line 73 of file Net.cc.

                                                         {
  remove_object(o->get_object_id());
}
void Net::remove_object ( object_id_t  o) [protected, virtual]

Remove object.

See also:
remove_object()

Definition at line 58 of file Net.cc.

References connections.

                                       {

  if(oid == 0)
    throw InvalidObjectIDException("The object that has to be "
                                   "removed from the net has no object ID.");

  connection_iterator i = connections.find(oid);
  if(i != connections.end()) {
    connections.erase(i);
  }
  else
    throw CollectionLookupException("Can't remove object from the the net, "
                                    "because it is not in the net.");
}
unsigned int Net::size ( ) const [virtual]

Get the number of objects that are connected with this net.

Definition at line 92 of file Net.cc.

References connections.

                             {
  return connections.size();
}

Friends And Related Function Documentation

friend class ConnectedLogicModelObject [friend]

Definition at line 55 of file Net.h.


Member Data Documentation

Definition at line 59 of file Net.h.

Referenced by add_object(), begin(), cloneDeepInto(), end(), remove_object(), and size().


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