Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members

pana_device_id.h

00001 /* BEGIN_COPYRIGHT                                                        */
00002 /*                                                                        */
00003 /* Open Diameter: Open-source software for the Diameter and               */
00004 /*                Diameter related protocols                              */
00005 /*                                                                        */
00006 /* Copyright (C) 2002-2004 Open Diameter Project                          */
00007 /*                                                                        */
00008 /* This library is free software; you can redistribute it and/or modify   */
00009 /* it under the terms of the GNU Lesser General Public License as         */
00010 /* published by the Free Software Foundation; either version 2.1 of the   */
00011 /* License, or (at your option) any later version.                        */
00012 /*                                                                        */
00013 /* This library 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 GNU      */
00016 /* Lesser General Public License for more details.                        */
00017 /*                                                                        */
00018 /* You should have received a copy of the GNU Lesser General Public       */
00019 /* License along with this library; if not, write to the Free Software    */
00020 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307    */
00021 /* USA.                                                                   */
00022 /*                                                                        */
00023 /* In addition, when you copy and redistribute some or the entire part of */
00024 /* the source code of this software with or without modification, you     */
00025 /* MUST include this copyright notice in each copy.                       */
00026 /*                                                                        */
00027 /* If you make any changes that are appeared to be useful, please send    */
00028 /* sources that include the changed part to                               */
00029 /* diameter-developers@lists.sourceforge.net so that we can reflect your  */
00030 /* changes to one unified version of this software.                       */
00031 /*                                                                        */
00032 /* END_COPYRIGHT                                                          */
00033 
00034 #ifndef __PANA_DEVICE_ID_H__
00035 #define __PANA_DEVICE_ID_H__
00036 
00037 #include <string>
00038 #include <list>
00039 #include "ace/OS.h"
00040 
00058 class PANA_DeviceId
00059 {
00060     public:
00061         typedef enum {
00062            UNKNOWN      = 0,
00063            IPV4_ADDRESS = 1,
00064            IPV6_ADDRESS = 2,
00065            LL_ADDRESS   = 3 
00066         } TYPE;
00067 
00068     public:
00069         PANA_DeviceId(PANA_DeviceId::TYPE type, std::string &id) :
00070             m_Type(type), m_Id(id) {
00071         }
00072         PANA_DeviceId(PANA_DeviceId::TYPE type) : m_Type(type) {
00073         }
00074         PANA_DeviceId() {
00075         }
00076         void type(PANA_DeviceId::TYPE t) {
00077             m_Type = t;
00078         }
00079         PANA_DeviceId::TYPE type() {
00080             return m_Type;
00081         }
00082         const std::string &id() {
00083             return m_Id;
00084         }
00085         bool operator==(PANA_DeviceId &cmp) {
00086             return (ACE_OS::memcmp(m_Id.data(), cmp.id().data(),
00087                     m_Id.size()) == 0);
00088         }
00089         PANA_DeviceId &operator=(PANA_DeviceId &src) {
00090             m_Type = src.type();
00091             m_Id.assign(src.id().data(), src.id().size());
00092             return (*this);
00093         }
00094 
00095     protected:
00096         TYPE m_Type;
00097         std::string m_Id;
00098 };
00099 
00100 typedef std::list<PANA_DeviceId*>::iterator  PANA_DeviceIdIterator;
00101 
00102 class PANA_DeviceIdContainer : public std::list<PANA_DeviceId*>
00103 {
00104     public:
00105         virtual ~PANA_DeviceIdContainer() {
00106             clear();
00107         }
00108         PANA_DeviceId *search(PANA_DeviceId::TYPE type) {
00109             PANA_DeviceId *id;
00110             PANA_DeviceIdIterator i;
00111             for (i = begin(); i != end(); i++) {
00112                 id = *i;
00113                 if (id->type() == type) {
00114                     return id;
00115                 }
00116             }
00117             return (NULL);
00118         }
00119         void replace(PANA_DeviceId &id) {
00120             PANA_DeviceId *old = search(id.type());
00121             if (old) {
00122                 const_cast<std::string&>(old->id()).assign
00123                     (id.id().data(), id.id().size());                
00124             }
00125         }
00126         void move(PANA_DeviceIdContainer &c) {
00127             while (! c.empty()) {
00128                 PANA_DeviceId *id = c.front();
00129                 c.pop_front();
00130                 push_back(id);
00131             }
00132         }
00133         void move(PANA_DeviceIdContainer &c,
00134                   PANA_DeviceId &id) {
00135             PANA_DeviceId *entry;
00136             PANA_DeviceIdIterator i;
00137             for (i = c.begin(); i != c.end(); i++) {
00138                 entry = *i;
00139                 if (entry == &id) {
00140                     c.erase(i);
00141                     push_back(entry);
00142                     return;
00143                 }
00144             }
00145         }
00146         void clone(PANA_DeviceIdContainer &c) {
00147             PANA_DeviceId *id;
00148             PANA_DeviceIdIterator i;
00149             for (i = c.begin(); i != c.end(); i++) {
00150                 id = *i;
00151                 clone(*id);
00152             }
00153         }
00154         void clone(PANA_DeviceId &id) {
00155             PANA_DeviceId *newId;
00156             ACE_NEW_NORETURN(newId, PANA_DeviceId(id.type()));
00157             if (newId) {
00158                 const_cast<std::string&>(newId->id()).assign
00159                     (id.id().data(), id.id().size());
00160             }
00161             push_back(newId);
00162         }
00163         void clear() {
00164             while (! empty()) {
00165                 PANA_DeviceId *id = front();
00166                 pop_front();
00167                 delete id;
00168             }
00169         }
00170 };
00171 
00172 #endif // __PANA_DEVICE_ID_H__
00173 

Generated on Fri Jun 25 19:18:29 2004 for PANA by doxygen 1.3.5