sprint 1-alpha
|
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_ALIASMAP_H 00022 #define _SPRINT_ALIASMAP_H 00023 00027 #include <map> 00028 #include <sprint/sysdef.h> 00029 #include <sprint/string/rstring.h> 00030 00031 namespace sprint { 00032 00035 class alias_map { 00036 // TODO: Comparison function 00037 char *pool; 00038 unsigned int cur_pos; 00039 unsigned int pool_size; 00040 00041 struct ltstr 00042 { 00043 bool operator()(const char *s1, const char *s2) const 00044 { 00045 return strcasecmp(s1, s2) < 0; 00046 } 00047 }; 00048 00049 typedef std::map<const char *, int, ltstr> map; 00050 typedef std::map<int, const char *> rmap; 00051 00052 // unique alias name 00053 const char *name; 00054 00055 // storage 00056 map ref; 00057 rmap rref; 00058 00059 // buffer for IO (contain 32 bit int string) 00060 char buffer[16]; 00061 00062 protected: 00063 void resize(unsigned int __new_size); 00064 00065 public: 00066 AliasMap(const char *_name=NULL); 00067 AliasMap(const AliasMap &src); 00068 ~AliasMap(); 00069 00071 bool push(const char *string, int val); 00072 00074 int operator[](const char *string); 00077 const char *operator [] (int value); 00078 00080 bool load(const char *file); 00081 bool save(const char *file); 00082 }; 00083 00085 extern void RegisterAlias(Alias *als); 00086 00087 } 00088 00089 #endif 00090