|
degate 0.1.1
|
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 00007 Degate is free software: you can redistribute it and/or modify 00008 it under the terms of the GNU General Public License as published by 00009 the Free Software Foundation, either version 3 of the License, or 00010 any later version. 00011 00012 Degate is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 GNU General Public License for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with degate. If not, see <http://www.gnu.org/licenses/>. 00019 00020 */ 00021 00022 #ifndef __OBJECTSET_H__ 00023 #define __OBJECTSET_H__ 00024 00025 #include <degate.h> 00026 #include <set> 00027 #include <list> 00028 #include <tr1/memory> 00029 #include <boost/foreach.hpp> 00030 00031 namespace degate { 00032 00033 /** 00034 * Returns true if the object can be removed from the Logic Model. 00035 */ 00036 bool is_removable(PlacedLogicModelObject_shptr o); 00037 00038 /** 00039 * Check if an object can be electrically interconnected with another object. 00040 */ 00041 bool is_interconnectable(PlacedLogicModelObject_shptr o); 00042 00043 template<typename Type> 00044 bool is_of_object_type(PlacedLogicModelObject_shptr o) { 00045 return std::tr1::dynamic_pointer_cast<Type>(o) != NULL; 00046 } 00047 00048 class ObjectSet { 00049 00050 public: 00051 typedef std::set<PlacedLogicModelObject_shptr> object_set_type; 00052 typedef object_set_type::const_iterator const_iterator; 00053 typedef object_set_type::iterator iterator; 00054 00055 private: 00056 object_set_type objects; 00057 00058 public: 00059 virtual ~ObjectSet() {} 00060 virtual void clear(); 00061 virtual void add(PlacedLogicModelObject_shptr object); 00062 virtual void remove(PlacedLogicModelObject_shptr object); 00063 00064 size_t size() const { return objects.size(); } 00065 00066 const_iterator begin() const { return objects.begin(); } 00067 const_iterator end() const { return objects.end(); } 00068 iterator begin() { return objects.begin(); } 00069 iterator end() { return objects.end(); } 00070 00071 bool empty() const { return objects.empty(); } 00072 00073 bool contains(PlacedLogicModelObject_shptr o) const { return objects.find(o) != objects.end(); } 00074 /** 00075 * Check if all objects evaluate to true for a check. 00076 * If there are no objects, false is returned. 00077 */ 00078 bool check_for_all(bool (*check_function)(PlacedLogicModelObject_shptr)) const { 00079 if(empty()) return false; 00080 00081 BOOST_FOREACH(PlacedLogicModelObject_shptr o, objects) { 00082 if(check_function(o) == false) return false; 00083 } 00084 return true; 00085 } 00086 00087 template<typename ObjectType> 00088 std::tr1::shared_ptr<ObjectType> get_single_object() const { 00089 std::tr1::shared_ptr<ObjectType> o; 00090 00091 if(size() == 1) { 00092 const_iterator it = objects.begin(); 00093 if(o = std::tr1::dynamic_pointer_cast<ObjectType>(*it)) return o; 00094 } 00095 return o; 00096 } 00097 00098 }; 00099 } 00100 00101 #endif
1.7.4