xorp

attribute_manager.hh

00001 // -*- c-basic-offset: 4; tab-width: 8; indent-tabs-mode: t -*-
00002 
00003 // Copyright (c) 2001-2011 XORP, Inc and Others
00004 //
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License, Version 2, June
00007 // 1991 as published by the Free Software Foundation. Redistribution
00008 // and/or modification of this program under the terms of any other
00009 // version of the GNU General Public License is not permitted.
00010 // 
00011 // This program is distributed in the hope that it will be useful, but
00012 // WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For more details,
00014 // see the GNU General Public License, Version 2, a copy of which can be
00015 // found in the XORP LICENSE.gpl file.
00016 // 
00017 // XORP Inc, 2953 Bunker Hill Lane, Suite 204, Santa Clara, CA 95054, USA;
00018 // http://xorp.net
00019 
00020 // $XORP: xorp/bgp/attribute_manager.hh,v 1.12 2008/11/08 06:14:36 mjh Exp $
00021 
00022 #ifndef __BGP_ATTRIBUTE_MANAGER_HH__
00023 #define __BGP_ATTRIBUTE_MANAGER_HH__
00024 
00025 
00026 #include "path_attribute.hh"
00027 
00028 template <class A>
00029 class PathAttributeList;
00030 
00031 #if 0
00032 template <class A>
00033 class StoredAttributeList {
00034 public:
00035     StoredAttributeList(const PathAttributeList<A> *att) {
00036     _attribute_list = att;
00037     _references = 1;
00038     }
00039 
00040     ~StoredAttributeList() {
00041     if (_references == 0) {
00042         delete _attribute_list;
00043     }
00044     }
00045 
00046     int references() const { return _references; }
00047     void increase() { _references++; }
00048     void decrease() { _references--; }
00049     void clone_data() {
00050     _attribute_list = new PathAttributeList<A>(*_attribute_list);
00051     }
00052     const PathAttributeList<A> *attribute() const { return _attribute_list; }
00053     const uint8_t* hash() const { return _attribute_list->hash(); }
00054     bool operator<(const StoredAttributeList<A>& them) const;
00055 private:
00056     const PathAttributeList<A> *_attribute_list;
00057     int _references;
00058 };
00059 
00060 #endif
00061 
00068 template <class A>
00069 class Att_Ptr_Cmp {
00070 public:
00071     bool operator() (const PAListRef<A>& a, const PAListRef<A>& b) const {
00072 /*  printf("Att_Ptr_Cmp [%s] < [%s] ?\n", a->attribute()->str().c_str(),
00073     b->attribute()->str().c_str());*/
00074 #ifdef OLDWAY
00075     if (*(a->attribute()) < *(b->attribute())) {
00076         //      printf("true\n");
00077         return true;
00078     } else {
00079         //      printf("false\n");
00080         return false;
00081     }
00082 #else
00083     return a < b;
00084 #endif
00085     }
00086 };
00087 
00096 template <class A>
00097 class AttributeManager {
00098 public:
00099     AttributeManager();
00100     PAListRef<A> add_attribute_list(PAListRef<A>& attribute_list);
00101     void delete_attribute_list(PAListRef<A>& attribute_list);
00102     int number_of_managed_atts() const {
00103     return _attribute_lists.size();
00104     }
00105 private:
00106     // set above for explanation of Att_Ptr_Cmp
00107     set <PAListRef<A>, Att_Ptr_Cmp<A> > _attribute_lists;
00108     int _total_references;
00109 };
00110 
00111 #endif // __BGP_ATTRIBUTE_MANAGER_HH__
 All Classes Namespaces Functions Variables Typedefs Enumerations