Qucs-core  0.0.19
nodelist.h
Go to the documentation of this file.
00001 /*
00002  * nodelist.h - node list class definitions
00003  *
00004  * Copyright (C) 2003, 2004, 2008 Stefan Jahn <stefan@lkcc.org>
00005  *
00006  * This is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU General Public License as published by
00008  * the Free Software Foundation; either version 2, or (at your option)
00009  * any later version.
00010  *
00011  * This software is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this package; see the file COPYING.  If not, write to
00018  * the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
00019  * Boston, MA 02110-1301, USA.
00020  *
00021  * $Id$
00022  *
00023  */
00024 
00025 #ifndef __NODELIST_H__
00026 #define __NODELIST_H__
00027 
00028 #include <vector>
00029 #include <list>
00030 #include <memory>
00031 #include <algorithm>
00032 
00033 namespace qucs {
00034 
00035 class node;
00036 class net;
00037 
00038 namespace detail {
00039   typedef std::vector<node *> nodevector;
00040 }
00041 
00042 struct nodelist_t {
00043 public:
00044   nodelist_t(const std::string &n="", bool intern = false) :
00045     n(0), name(n), internal(intern), nodes() {}
00046 
00047   nodelist_t(nodelist_t &c) = default;
00048 
00049   typedef detail::nodevector::value_type value_type;
00050   typedef detail::nodevector::iterator iterator;
00051   typedef detail::nodevector::const_iterator const_iterator;
00052   typedef detail::nodevector::size_type size_type;
00053   typedef detail::nodevector::reference reference;
00054   typedef detail::nodevector::const_reference const_reference;
00055 #ifdef HAVE_ERASE_CONSTANT_ITERATOR
00056   typedef detail::nodevector::const_iterator erase_iterator;
00057 #else
00058   typedef detail::nodevector::iterator erase_iterator;
00059 #endif
00060 
00062   std::size_t n;
00064   std::string name;
00065   bool internal;
00066 
00067   reference operator[] (size_type n) {
00068     return (this->nodes[n]);
00069   }
00070   const_reference operator[] (size_type n) const {
00071     return (this->nodes[n]);
00072   }
00073 
00074   size_type size() const noexcept {
00075     return nodes.size();
00076   }
00077 
00078   void push_back(const value_type &val) {
00079     this->nodes.push_back(val);
00080   }
00081 
00082   iterator begin() noexcept {
00083     return nodes.begin();
00084   }
00085   const_iterator begin() const noexcept {
00086     return nodes.begin();
00087   }
00088   iterator end() noexcept {
00089     return nodes.end();
00090   }
00091   const_iterator end() const noexcept {
00092     return nodes.end();
00093   }
00094   iterator erase (erase_iterator position)
00095   { return nodes.erase(position); };
00096   iterator erase (erase_iterator first, erase_iterator last)
00097   { return nodes.erase(first,last); };
00098 
00099   bool empty() const noexcept {
00100     return nodes.empty();
00101   }
00102 private:
00103   std::vector<value_type> nodes;
00104 };
00105 
00106 class nodelist
00107 {
00108  public:
00109   // Constructor creates an instance of the nodelist class.
00110   nodelist () :  narray(), sorting(0) {
00111   }
00112   nodelist (net *);
00113   ~nodelist ();
00114   int length (void) const ;
00115   int getNodeNr (const std::string &) const ;
00116   std::string get (int) const ;
00117   bool isInternal (int) const ;
00118   void assignNodes (void);
00119   void print (void) const;
00120   std::string getNodeString (int) const;
00121   void sort (void);
00122   void remove (circuit *);
00123   void insert (circuit *);
00124   void sortedNodes (node **, node **);
00125   struct nodelist_t * getNode (const std::string &) const;
00126   struct nodelist_t * getNode (int nr) const {
00127     return narray[nr + 1];
00128   }
00129   nodelist_t &operator[](int nr) const {
00130     return *narray[nr + 1];
00131   }
00132 
00133  private:
00134   std::vector<nodelist_t *> narray;
00135   std::list<nodelist_t *> root;
00136   int sorting;
00137   bool contains (const std::string &) const;
00138   void insert (struct nodelist_t *);
00139   void addCircuitNode (struct nodelist_t *, node *);
00140 };
00141 
00142 } // namespace qucs
00143 
00144 #endif /* __NODELIST_H__ */