Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members | Related Pages | Examples

vos/corelibs/typechain/typehandler.hh

Go to the documentation of this file.
00001 /* $Id: typehandler.hh,v 1.17 2003/07/24 17:37:44 tetron Exp $ */
00002 
00003 /** @file typehandler.hh    defines a rudimentary type handler from which
00004     you may derive specific type handlers, and a type handler which passes
00005     data through an external program.
00006     @author Reed sept 2001
00007 */
00008 
00009 /*
00010     This file is part of the Virtual Object System of
00011     the Interreality project (http://interreality.org).
00012 
00013     Copyright (C) 2001, 2002 Reed Hedges <reed@zerohour.net>
00014 
00015     This library is free software; you can redistribute it and/or
00016     modify it under the terms of the GNU Lesser General Public
00017     License as published by the Free Software Foundation; either
00018     version 2 of the License, or (at your option) any later version.
00019 
00020     This library is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00023     Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public
00026     License along with this library; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
00028 */
00029 
00030 #ifndef _TYPEHANDLER_HH_
00031 #define _TYPEHANDLER_HH_
00032 
00033 #include <string>
00034 #include <map>
00035 #include <stdio.h>
00036 #include "typechain.hh"
00037 
00038 
00039 
00040 
00041 
00042 
00043 typedef std::map<std::string, std::string> TypeParams;
00044 
00045 /** Derive your specific type handlers from this class, for use with the TypeChain
00046     utility. As is, it implements the "identity" encoding, as described in the
00047     typechain document ($CVSROOT/s3/doc/typechain.txt), and similiar to encodings
00048     mentioned in various RFCs.
00049     @TODO add methods that use streams.
00050     @see TypeChain
00051     @author Reed Hedges <reed@zerohour.net> September, 2001
00052 */
00053 
00054 class TypeHandler  {
00055 public:
00056 
00057     /** Type/encoding identifier  */
00058     string type_name;
00059 
00060     /** A common filename extension for this type. (Used by TypeChain::guessTypeFromFilename()) */
00061     string filename_extension;
00062 
00063     /** Constructor */
00064     TypeHandler(string name, string file_ext = "?") : type_name(name), filename_extension(file_ext) {}
00065 
00066     /** Destructor */
00067     virtual ~TypeHandler() {};
00068 
00069     /** Decode data with parameters params. This class implements the "identity" type, and does no decoding. */
00070     virtual void decode(std::string& data, TypeParams& params)  {
00071     }
00072 
00073     /** Create empty params map and decode. */
00074     void decode(std::string& data) {
00075         TypeParams empty;
00076         decode(data, empty);
00077     }
00078 
00079     /** Encode data with parameters params. This class implements the "identity" type, and does no encoding. */
00080     virtual void encode(std::string& data, TypeParams& params) {
00081     }
00082 
00083     /** Create empty params map and encode. */
00084     void encode(std::string& data) {
00085         TypeParams empty;
00086         encode(data, empty);
00087     }
00088 
00089 };
00090 
00091 
00092 
00093 #endif

Generated on Tue Aug 12 03:55:39 2003 for Interreality Project - VOS by doxygen 1.3.2