sprint 1-alpha
sprint/container/alias.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 *   sprint::alias
00003 *
00004 *   Copyright (C) 2005-2011  Paolo Medici <www.pmx.it>
00005 *
00006 *  This library is free software; you can redistribute it and/or
00007 *  modify it under the terms of the GNU Lesser General Public
00008 *  License as published by the Free Software Foundation; either
00009 *  version 2.1 of the License, or (at your option) any later version.
00010 *
00011 *  This library 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 GNU
00014 *  Lesser General Public License for more details.
00015 *
00016 *  You should have received a copy of the GNU Lesser General Public
00017 *  License along with this library; if not, write to the Free Software
00018 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 *
00020 *******************************************************************************/
00021 #ifndef _SPRINT_ALIAS_H
00022 #define _SPRINT_ALIAS_H
00023 
00027 #include <vector>
00028 
00029 namespace sprint {
00030 
00036 class alias {
00037 public:
00038         const char *name;
00039 protected:
00041         const char **ptr;
00042 
00044         unsigned int n_alias;
00046         unsigned int n_max_alias;
00047 
00048 public:
00049         alias();
00051         alias(const char *static_name);
00052         alias(const alias &src);
00053         ~alias();
00054 
00056         bool allocate(int _alias);
00057 
00059         inline const char **list() const
00060         {
00061                 return ptr;
00062         }
00063 
00066         int operator[](const char *strtocompare) const;
00067         
00069         int append(const char *string);
00070         
00072         unsigned int memoryused();
00073         
00076         const char *operator[](int i);
00077 
00079         bool save(const char *file);
00081         bool load(const char *file);
00082 
00083 };
00084 
00086 template<class T>
00087 class alias_vector {
00088     std::vector<T> ptr;
00089 public:
00090         alias_vector() {} 
00091         alias_vector(const alias_vector<T> &src) : ptr(src) { }
00092         ~alias_vector() {} 
00093 
00094         inline T * list() {
00095                 return &ptr[0];
00096         }
00097         inline const T * list() const {
00098                 return &ptr[0];
00099         }
00100   
00103     template<class R>
00104         int operator[](R target) const {
00105         for(int i=0;i<ptr.size();++i)
00106                 if( target == ptr[i])
00107                   return i;
00108         return -1;
00109     }
00110 
00112         inline int append(const T & d) { ptr.push_back(d); }
00113 
00115         const T & operator[](int i) const { return ptr[i]; }
00116 
00117 //      bool save(const char *file) {}
00118 //      bool load(const char *file) {}
00119 };
00120 
00122 template<class T>
00123 class named_alias_vector : public alias_vector<T> {
00124 
00125       public:
00126       const char *name;
00127 
00128       public:
00129 };
00130 
00131 
00132 } // sprint
00133 
00134 
00135 #endif
00136 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines