00001 /* 00002 * HT Editor 00003 * htatom.cc 00004 * 00005 * Copyright (C) 1999-2002 Stefan Weyergraf (stefan@weyergraf.de) 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License version 2 as 00009 * published by the Free Software Foundation. 00010 * 00011 * This program 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 program; if not, write to the Free Software 00018 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00019 */ 00020 00021 #include "htatom.h" 00022 #include "htdata.h" 00023 00024 #include <string.h> 00025 00026 ht_stree *atoms; 00027 00028 void *find_atom(HT_ATOM atom) 00029 { 00030 if (atom) { // atom 0 is special ! 00031 ht_data_uint a(atom); 00032 ht_data_ptr *d=(ht_data_ptr*)atoms->get(&a); 00033 if (d) return (void*)d->value; 00034 } 00035 return NULL; 00036 } 00037 00038 HT_ATOM find_atom_rev(const void *data) 00039 { 00040 if (data) { 00041 ht_data_uint *key=NULL; 00042 ht_data_ptr *value; 00043 while ((key=(ht_data_uint*)atoms->enum_next((Object**)&value, key))) { 00044 if (value->value==data) return key->value; 00045 } 00046 } 00047 return 0; 00048 } 00049 00050 bool register_atom(HT_ATOM atom, const void *data) 00051 { 00052 if (!find_atom(atom)) { 00053 atoms->insert(new ht_data_uint(atom), new ht_data_ptr(data)); 00054 return true; 00055 } 00056 return false; 00057 } 00058 00059 bool unregister_atom(HT_ATOM atom) 00060 { 00061 ht_data_uint a(atom); 00062 atoms->del(&a); 00063 return true; 00064 } 00065 00066 /* 00067 * INIT 00068 */ 00069 00070 bool init_atom() 00071 { 00072 atoms=new ht_stree(); 00073 atoms->init(compare_keys_uint); 00074 return true; 00075 } 00076 00077 /* 00078 * DONE 00079 */ 00080 00081 void done_atom() 00082 { 00083 atoms->destroy(); 00084 delete atoms; 00085 } 00086