[150] | 1 | /**********************************************************************
|
---|
| 2 | *
|
---|
| 3 | * converter.h --
|
---|
| 4 | * Copyright (C) 1999 The New Zealand Digital Library Project
|
---|
| 5 | *
|
---|
[533] | 6 | * A component of the Greenstone digital library software
|
---|
| 7 | * from the New Zealand Digital Library Project at the
|
---|
| 8 | * University of Waikato, New Zealand.
|
---|
[150] | 9 | *
|
---|
[533] | 10 | * This program is free software; you can redistribute it and/or modify
|
---|
| 11 | * it under the terms of the GNU General Public License as published by
|
---|
| 12 | * the Free Software Foundation; either version 2 of the License, or
|
---|
| 13 | * (at your option) any later version.
|
---|
| 14 | *
|
---|
| 15 | * This program is distributed in the hope that it will be useful,
|
---|
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 18 | * GNU General Public License for more details.
|
---|
| 19 | *
|
---|
| 20 | * You should have received a copy of the GNU General Public License
|
---|
| 21 | * along with this program; if not, write to the Free Software
|
---|
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 23 | *
|
---|
[150] | 24 | *********************************************************************/
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | #ifndef CONVERTER_H
|
---|
| 28 | #define CONVERTER_H
|
---|
| 29 |
|
---|
| 30 |
|
---|
| 31 | #include "gsdlconf.h"
|
---|
| 32 | #include "text_t.h"
|
---|
| 33 | #include "gsdlunicode.h"
|
---|
| 34 |
|
---|
| 35 | #if defined(GSDL_USE_OBJECTSPACE)
|
---|
| 36 | # include <ospace\std\map>
|
---|
| 37 | #elif defined(GSDL_USE_STL_H)
|
---|
| 38 | # include <map.h>
|
---|
| 39 | #else
|
---|
| 40 | # include <map>
|
---|
| 41 | #endif
|
---|
| 42 |
|
---|
| 43 |
|
---|
[164] | 44 | // inconverter and outconverter ARE NOT destroyed by this class
|
---|
| 45 | // they should be destroyed by the code which created them after
|
---|
| 46 | // no more pointers to the class exist.
|
---|
| 47 | //
|
---|
| 48 | // The above condition enables the class to be copied without
|
---|
| 49 | // copying the converters which might contain a lot of data (and
|
---|
| 50 | // be of an unknown derived type).
|
---|
[150] | 51 | class converterinfo {
|
---|
| 52 | public:
|
---|
| 53 | text_t name;
|
---|
| 54 | inconvertclass *inconverter;
|
---|
| 55 | rzwsoutconvertclass *outconverter;
|
---|
| 56 |
|
---|
| 57 | converterinfo() {inconverter=NULL; outconverter=NULL;}
|
---|
| 58 | };
|
---|
| 59 |
|
---|
[509] | 60 | bool operator==(const converterinfo &x, const converterinfo &y);
|
---|
| 61 | bool operator<(const converterinfo &x, const converterinfo &y);
|
---|
[150] | 62 |
|
---|
| 63 |
|
---|
| 64 | typedef map<text_t, converterinfo, lttext_t> convertmap;
|
---|
| 65 |
|
---|
| 66 | // convertinfoclass is used to store a number of converters
|
---|
| 67 | // indexing them by their name
|
---|
| 68 | class convertinfoclass {
|
---|
| 69 | protected:
|
---|
| 70 | convertmap converters;
|
---|
| 71 |
|
---|
| 72 | public:
|
---|
| 73 | // type support for convertmap
|
---|
| 74 | typedef convertmap::iterator iterator;
|
---|
| 75 | typedef convertmap::const_iterator const_iterator;
|
---|
| 76 | typedef convertmap::reference reference;
|
---|
| 77 | typedef convertmap::const_reference const_reference;
|
---|
| 78 | typedef convertmap::size_type size_type;
|
---|
| 79 | typedef convertmap::difference_type difference_type;
|
---|
| 80 | typedef convertmap::const_reverse_iterator const_reverse_iterator;
|
---|
| 81 | typedef convertmap::reverse_iterator reverse_iterator;
|
---|
| 82 |
|
---|
| 83 | // constructors
|
---|
| 84 | convertinfoclass () {}
|
---|
| 85 |
|
---|
| 86 | // basic container support
|
---|
| 87 | iterator begin () {return converters.begin();}
|
---|
| 88 | const_iterator begin () const {return converters.begin();}
|
---|
| 89 | iterator end () {return converters.end();}
|
---|
| 90 | const_iterator end () const {return converters.end();}
|
---|
| 91 |
|
---|
| 92 | void erase(iterator pos) {converters.erase(pos);}
|
---|
| 93 | void erase(iterator first, iterator last) {converters.erase(first, last);}
|
---|
| 94 | convertinfoclass &operator=(const convertinfoclass &x)
|
---|
| 95 | {converters=x.converters;return *this;}
|
---|
| 96 |
|
---|
| 97 | bool empty () const {return converters.empty();}
|
---|
| 98 | size_type size() const {return converters.size();}
|
---|
| 99 |
|
---|
[1876] | 100 | const_iterator find(text_t &key) {return converters.find(key);}
|
---|
[150] | 101 |
|
---|
| 102 | // added functionality
|
---|
| 103 | void clear () {converters.erase(converters.begin(),converters.end());}
|
---|
| 104 |
|
---|
| 105 | // the converters within converterinfo become the property of
|
---|
[164] | 106 | // of this class after add_converter has been called. The converters
|
---|
| 107 | // remain the responsability of the calling code and will not be
|
---|
| 108 | // deleted by this class.
|
---|
[150] | 109 | void add_converter (const text_t &name, inconvertclass *inconverter,
|
---|
| 110 | rzwsoutconvertclass *outconverter);
|
---|
| 111 |
|
---|
| 112 | // get_inconverter will return NULL if the convert could not be found
|
---|
| 113 | inconvertclass *get_inconverter (const text_t &name);
|
---|
| 114 |
|
---|
| 115 | // get_outconverter will return NULL if the convert could not be found
|
---|
| 116 | rzwsoutconvertclass *get_outconverter (const text_t &name);
|
---|
| 117 | };
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | #endif
|
---|