degate  0.1.2
Net.h
Go to the documentation of this file.
00001 /* -*-c++-*-
00002 
00003  This file is part of the IC reverse engineering tool degate.
00004 
00005  Copyright 2008, 2009, 2010 by Martin Schobert
00006  Copyright 2012 Robert Nitsch
00007 
00008  Degate is free software: you can redistribute it and/or modify
00009  it under the terms of the GNU General Public License as published by
00010  the Free Software Foundation, either version 3 of the License, or
00011  any later version.
00012 
00013  Degate is distributed in the hope that it will be useful,
00014  but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016  GNU General Public License for more details.
00017 
00018  You should have received a copy of the GNU General Public License
00019  along with degate. If not, see <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifndef __NET_H__
00024 #define __NET_H__
00025 
00026 #include <set>
00027 #include <memory>
00028 
00029 
00030 #include "globals.h"
00031 
00032 
00033 namespace degate {
00034 
00035 
00036   /**
00037    * The net class represents an electrical potential that is shared
00038    * between electrically adjacent objects.
00039    *
00040    * Why do methods in class Net work with object ID instead of
00041    * shared pointers? There is an automatism. A ConnectedLogicModelObject
00042    * adds itself to a net, if you set the net for the ConnectedLogicModelObject.
00043    * And it removes itself from a Net object, if it's destructor is called.
00044    * The problem is, that the ConnectedLogicModelObject itself only
00045    * has a \p this pointer. An object can't have a shared pointer to itself.
00046    * One could work with normal pointers, but this would somehow circumvent
00047    * shared pointer approach in libdegate. So we use loosely coupled
00048    * object IDs.
00049    *
00050    * @see ConnectedLogicModelObject::set_net()
00051    * @see ConnectedLogicModelObject::remove_net()
00052    */
00053   class Net : public LogicModelObjectBase, public DeepCopyable {
00054 
00055     friend class ConnectedLogicModelObject;
00056 
00057   private:
00058 
00059     std::set<object_id_t> connections;
00060 
00061   protected:
00062 
00063     /**
00064      * Add an object of type ConnectedLogicModelObject to the net.
00065      * It is silently ignored, if the object is already referenced
00066      * from the net.
00067      * @exception InvalidObjectIDException This exception is thrown
00068      *  if the object has an invalid object ID.
00069      */
00070 
00071     virtual void add_object(ConnectedLogicModelObject_shptr o);
00072 
00073 
00074     /**
00075      * Add an object to the net.
00076      * @see add_object()
00077      */
00078     virtual void add_object(object_id_t oid);
00079 
00080 
00081     /**
00082      * Remove an object from a net.
00083      * @exception CollectionLookupException Indicates that the object
00084      *  is not referenced from the net.
00085      * @exception InvalidObjectIDException As in add_object().
00086      * @see add_object()
00087      */
00088 
00089     virtual void remove_object(ConnectedLogicModelObject_shptr o);
00090 
00091     /**
00092      * Remove object.
00093      * @see remove_object()
00094      */
00095 
00096     virtual void remove_object(object_id_t o);
00097 
00098 
00099   public:
00100 
00101     typedef std::set<object_id_t>::iterator connection_iterator;
00102     typedef std::set<object_id_t>::iterator iterator;
00103     typedef std::set<object_id_t>::const_iterator const_iterator;
00104 
00105     /**
00106      * Construct a new net.
00107      */
00108     Net();
00109 
00110     /**
00111      * Destroy a net.
00112      * @see LogicModel::remove_net()
00113      */
00114     virtual ~Net();
00115     
00116     //@{
00117     DeepCopyable_shptr cloneShallow() const;
00118     void cloneDeepInto(DeepCopyable_shptr destination, oldnew_t *oldnew) const;
00119     //@}
00120 
00121     /**
00122      * Get an iterator to iterate over all objects that are electrically connected with this net.
00123      * Be careful with iterator invalidation!
00124      */
00125     virtual connection_iterator begin();
00126 
00127     /**
00128      * Get an end marker.
00129      */
00130     virtual connection_iterator end();
00131 
00132 
00133     /**
00134      * Get  the number of objects that are connected with this net.
00135      */
00136 
00137     virtual unsigned int size() const;
00138 
00139     /**
00140      * Get a human readable description for the object.
00141      */
00142     const std::string get_descriptive_identifier() const;
00143   };
00144 
00145 }
00146 
00147 #endif