encoder_factory.cc

Go to the documentation of this file.
00001 /*
00002    The lestes compiler suite
00003    Copyright (C) 2002, 2003, 2004, 2005 Miroslav Tichy
00004    Copyright (C) 2002, 2003, 2004, 2005 Petr Zika
00005    Copyright (C) 2002, 2003, 2004, 2005 Vojtech Hala
00006    Copyright (C) 2002, 2003, 2004, 2005 Jiri Kosina
00007    Copyright (C) 2002, 2003, 2004, 2005 Pavel Sanda
00008    Copyright (C) 2002, 2003, 2004, 2005 Jan Zouhar
00009    Copyright (C) 2002, 2003, 2004, 2005 Rudolf Thomas
00010 
00011    This program is free software; you can redistribute it and/or modify
00012    it under the terms of the GNU General Public License as published by
00013    the Free Software Foundation; version 2 of the License.
00014 
00015    This program is distributed in the hope that it will be useful,
00016    but WITHOUT ANY WARRANTY; without even the implied warranty of
00017    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018    GNU General Public License for more details.
00019 
00020    See the full text of the GNU General Public License version 2, and
00021    the limitations in the file doc/LICENSE.
00022 
00023    By accepting the license the licensee waives any and all claims
00024    against the copyright holder(s) related in whole or in part to the
00025    work, its use, and/or the inability to use it.
00026  
00027  */
00028 /*! \file
00029   \brief Factory for encoders.
00030   
00031   Definition of encoder_factory class managing encoder implementations.
00032   \author pt
00033 */
00034 #include <lestes/common.hh>
00035 #include <lestes/lang/cplus/lex/encoder_factory.hh>
00036 
00037 package(lestes);
00038 package(lang);
00039 package(cplus);
00040 package(lex);
00041 
00042 using namespace ::std;
00043 
00044 /*!
00045   Creates the object.
00046   \post summon() == NULL
00047 */
00048 encoder_factory::encoder_factory(void):
00049         storage(storage_type::create())
00050 {
00051 }
00052 
00053 /*!
00054   Inserts new encoder into the database.
00055   \pre a_create != NULL
00056   \pre a_create() != NULL (checked only in summon())
00057   \post summon(a_name) == a_create()
00058   \param a_name  The name of the encoder to insert.
00059   \param a_create  The method tho create the encoder.
00060 */
00061 void encoder_factory::insert(const lstring &a_name, encoder_create_type a_create)
00062 {
00063         lassert(a_create);
00064         storage->insert(storage_type::value_type(a_name,a_create));
00065 }
00066 
00067 /*!
00068   Removes encoder from the database.
00069   \pre a_name is in the database.
00070   \param a_name  The name of the encoder to remove.
00071 */
00072 void encoder_factory::remove(const lstring &a_name)
00073 {
00074         storage_type::iterator it = storage->find(a_name);
00075         lassert(it != storage->end());
00076         storage->erase(it);
00077 }
00078 
00079 /*!
00080   Returns new encoder for given name.
00081   \pre a_name was inserted into the factory
00082   \post returned != NULL or a_name was not inserted
00083   \param a_name  The name of the desired encoder.
00084   \return The new encoder or NULL if not found.
00085 */
00086 ptr<encoder> encoder_factory::summon(const lstring &a_name) const
00087 {
00088         storage_type::iterator it = storage->find(a_name);
00089         if (it == storage->end()) return NULL;
00090         // call the create function
00091         ptr<encoder> ret = (it->second)();
00092         // check whether the create succeeded
00093         lassert(ret);
00094         return ret;
00095 }
00096 
00097 /*!
00098   Marks the object.
00099 */
00100 void encoder_factory::gc_mark(void)
00101 {
00102         storage.gc_mark();
00103 	::lestes::std::object::gc_mark();
00104 }
00105 
00106 /*!
00107   Returns the only instance of the encoder_factory class.
00108   \return The singleton encoder_factory object.
00109 */
00110 ptr<encoder_factory> encoder_factory::instance(void)
00111 {
00112         if (!singleton) {
00113                 singleton = new encoder_factory();
00114         }
00115         return singleton;
00116 }
00117 
00118 /*!
00119   The only instance of the class, holds all encoder registrations.
00120   Uses lazy instantiation.
00121 */
00122 ptr<encoder_factory> encoder_factory::singleton;
00123 
00124 end_package(lex);
00125 end_package(cplus);
00126 end_package(lang);
00127 end_package(lestes);
00128 
00129 /* vim: set ft=lestes : */

Generated on Mon Feb 12 18:22:33 2007 for lestes by doxygen 1.5.1-20070107