pelib
2.0.0
|
00001 /* 00002 * map.h 00003 * 00004 * Created on: 5 Sep 2011 00005 * Copyright 2011 Nicolas Melot 00006 * 00007 * This file is part of pelib. 00008 * 00009 * pelib is free software: you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation, either version 3 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * pelib is distributed in the hope that it will be useful, 00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 * GNU General Public License for more details. 00018 * 00019 * You should have received a copy of the GNU General Public License 00020 * along with pelib. If not, see <http://www.gnu.org/licenses/>. 00021 * 00022 */ 00023 00024 #include <pelib/template.h> 00025 #if PELIB_CONCAT_4(DONE_map_, MAP_KEY_T, _, MAP_VALUE_T) == 0 00026 #define map(key, value) PELIB_CONCAT_4(map_, key, _, value) 00027 #define map_t(key, value) PELIB_CONCAT_2(map(key, value), _t) 00028 #define map_iterator(key, value) PELIB_CONCAT_2(map_, iterator(pair_t(key, value))) 00029 #define map_iterator_t(key, value) PELIB_CONCAT_2(map_iterator(key, value), _t) 00030 00031 /* 00032 #define PAIR_KEY_T MAP_KEY_T 00033 #define PAIR_VALUE_T MAP_VALUE_T 00034 #include <pelib/pair.h> 00035 */ 00036 00037 /* 00038 #define ITERATOR_T pair_t(MAP_KEY_T, MAP_VALUE_T) 00039 #include <pelib/iterator.h> 00040 */ 00041 00042 #define pelib_map_begin(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _begin) 00043 #define pelib_map_end(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _end) 00044 #define pelib_map_next(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _next) 00045 #define pelib_map_read(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _read) 00046 #define pelib_map_insert(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _insert) 00047 #define pelib_map_find(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _find) 00048 #define pelib_map_compare(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _compare) 00049 #define pelib_map_size(key, value) PELIB_CONCAT_3(pelib_, map(key, value), _size) 00050 00052 struct map(MAP_KEY_T, MAP_VALUE_T) 00053 { 00054 iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T)) *first, *last, *middle; 00055 }; 00056 typedef struct map(MAP_KEY_T, MAP_VALUE_T) map_t(MAP_KEY_T, MAP_VALUE_T); 00057 typedef struct iterator(pair_t(MAP_KEY_T, MAP_VALUE_T)) map_iterator_t(MAP_KEY_T, MAP_VALUE_T); 00058 00059 #define STRUCT_T map_t(MAP_KEY_T, MAP_VALUE_T) 00060 #include <pelib/structure.h> 00061 00062 /* Returns the first element in map */ 00063 iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))* 00064 pelib_map_begin(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)*); 00065 00066 /* Returns the first element in map */ 00067 iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))* 00068 pelib_map_end(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)*); 00069 00070 /* Places an element in map */ 00071 int 00072 pelib_map_insert(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)*, pair_t(MAP_KEY_T, MAP_VALUE_T)); 00073 00074 /* Find an element in map */ 00075 iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))* 00076 pelib_map_find(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)*, MAP_KEY_T); 00077 00081 int 00082 pelib_map_compare(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)* a1, map_t(MAP_KEY_T, MAP_VALUE_T)* a2); 00083 00084 iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))* 00085 pelib_map_next(MAP_KEY_T, MAP_VALUE_T)(iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))*); 00086 00087 pair_t(MAP_KEY_T, MAP_VALUE_T) 00088 pelib_map_read(MAP_KEY_T, MAP_VALUE_T)(iterator_t(pair_t(MAP_KEY_T, MAP_VALUE_T))*); 00089 00090 size_t 00091 pelib_map_size(MAP_KEY_T, MAP_VALUE_T)(map_t(MAP_KEY_T, MAP_VALUE_T)*); 00092 00093 #endif 00094 00095 // Make sure the symbol does not propagate any further 00096 #undef MAP_KEY_T 00097 #undef MAP_VALUE_T