| 1 | /* | 
|---|
| 2 | ----------------------------------------------------------------------------- | 
|---|
| 3 | This source file is part of OGRE | 
|---|
| 4 | (Object-oriented Graphics Rendering Engine) | 
|---|
| 5 | For the latest info, see http://www.ogre3d.org/ | 
|---|
| 6 |  | 
|---|
| 7 | Copyright (c) 2000-2006 Torus Knot Software Ltd | 
|---|
| 8 | Also see acknowledgements in Readme.html | 
|---|
| 9 |  | 
|---|
| 10 | This program is free software; you can redistribute it and/or modify it under | 
|---|
| 11 | the terms of the GNU Lesser General Public License as published by the Free Software | 
|---|
| 12 | Foundation; either version 2 of the License, or (at your option) any later | 
|---|
| 13 | version. | 
|---|
| 14 |  | 
|---|
| 15 | This program is distributed in the hope that it will be useful, but WITHOUT | 
|---|
| 16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | 
|---|
| 17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. | 
|---|
| 18 |  | 
|---|
| 19 | You should have received a copy of the GNU Lesser General Public License along with | 
|---|
| 20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple | 
|---|
| 21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to | 
|---|
| 22 | http://www.gnu.org/copyleft/lesser.txt. | 
|---|
| 23 |  | 
|---|
| 24 | You may alternatively use this source under the terms of a specific version of | 
|---|
| 25 | the OGRE Unrestricted License provided you have obtained such a license from | 
|---|
| 26 | Torus Knot Software Ltd. | 
|---|
| 27 | ----------------------------------------------------------------------------- | 
|---|
| 28 | */ | 
|---|
| 29 | #ifndef _Codec_H__ | 
|---|
| 30 | #define _Codec_H__ | 
|---|
| 31 |  | 
|---|
| 32 | #include "OgrePrerequisites.h" | 
|---|
| 33 | #include "OgreSharedPtr.h" | 
|---|
| 34 | #include "OgreDataStream.h" | 
|---|
| 35 | #include "OgreIteratorWrappers.h" | 
|---|
| 36 | #include "OgreStringVector.h" | 
|---|
| 37 |  | 
|---|
| 38 | namespace Ogre { | 
|---|
| 39 |  | 
|---|
| 40 |     /** Abstract class that defines a 'codec'. | 
|---|
| 41 |         @remarks | 
|---|
| 42 |             A codec class works like a two-way filter for data - data entered on | 
|---|
| 43 |             one end (the decode end) gets processed and transformed into easily | 
|---|
| 44 |             usable data while data passed the other way around codes it back. | 
|---|
| 45 |         @par | 
|---|
| 46 |             The codec concept is a pretty generic one - you can easily understand | 
|---|
| 47 |             how it can be used for images, sounds, archives, even compressed data. | 
|---|
| 48 |     */ | 
|---|
| 49 |     class _OgreExport Codec | 
|---|
| 50 |     { | 
|---|
| 51 |     protected: | 
|---|
| 52 |         typedef std::map< String, Codec* > CodecList;  | 
|---|
| 53 |         /** A map that contains all the registered codecs. | 
|---|
| 54 |         */ | 
|---|
| 55 |         static CodecList ms_mapCodecs; | 
|---|
| 56 |  | 
|---|
| 57 |     public: | 
|---|
| 58 |         class _OgrePrivate CodecData  | 
|---|
| 59 |         { | 
|---|
| 60 |         public: | 
|---|
| 61 |             virtual ~CodecData() {}; | 
|---|
| 62 |  | 
|---|
| 63 |             /** Returns the type of the data. | 
|---|
| 64 |             */ | 
|---|
| 65 |             virtual String dataType() const { return "CodecData"; }; | 
|---|
| 66 |         }; | 
|---|
| 67 |         typedef SharedPtr<CodecData> CodecDataPtr; | 
|---|
| 68 |  | 
|---|
| 69 |         typedef ConstMapIterator<CodecList> CodecIterator; | 
|---|
| 70 |  | 
|---|
| 71 |     public: | 
|---|
| 72 |         virtual ~Codec(); | 
|---|
| 73 |          | 
|---|
| 74 |         /** Registers a new codec in the database. | 
|---|
| 75 |         */ | 
|---|
| 76 |         static void registerCodec( Codec *pCodec ) | 
|---|
| 77 |         { | 
|---|
| 78 |             ms_mapCodecs[pCodec->getType()] = pCodec; | 
|---|
| 79 |         } | 
|---|
| 80 |  | 
|---|
| 81 |         /** Unregisters a codec from the database. | 
|---|
| 82 |         */ | 
|---|
| 83 |         static void unRegisterCodec( Codec *pCodec ) | 
|---|
| 84 |         { | 
|---|
| 85 |             ms_mapCodecs.erase(pCodec->getType()); | 
|---|
| 86 |         } | 
|---|
| 87 |  | 
|---|
| 88 |         /** Gets the iterator for the registered codecs. */ | 
|---|
| 89 |         static CodecIterator getCodecIterator(void) | 
|---|
| 90 |         { | 
|---|
| 91 |             return CodecIterator(ms_mapCodecs.begin(), ms_mapCodecs.end()); | 
|---|
| 92 |         } | 
|---|
| 93 |  | 
|---|
| 94 |         /** Gets the file extension list for the registered codecs. */ | 
|---|
| 95 |         static StringVector getExtensions(void); | 
|---|
| 96 |  | 
|---|
| 97 |         /** Gets the codec registered for the passed in file extension. */ | 
|---|
| 98 |         static Codec* getCodec(const String& extension); | 
|---|
| 99 |  | 
|---|
| 100 |         /** Codes the data in the input stream and saves the result in the output | 
|---|
| 101 |             stream. | 
|---|
| 102 |         */ | 
|---|
| 103 |         virtual DataStreamPtr code(MemoryDataStreamPtr& input, CodecDataPtr& pData) const = 0; | 
|---|
| 104 |         /** Codes the data in the input chunk and saves the result in the output | 
|---|
| 105 |             filename provided. Provided for efficiency since coding to memory is | 
|---|
| 106 |             progressive therefore memory required is unknown leading to reallocations. | 
|---|
| 107 |         @param input The input data | 
|---|
| 108 |         @param outFileName The filename to write to | 
|---|
| 109 |         @param pData Extra information to be passed to the codec (codec type specific) | 
|---|
| 110 |         */ | 
|---|
| 111 |         virtual void codeToFile(MemoryDataStreamPtr& input, const String& outFileName, CodecDataPtr& pData) const = 0; | 
|---|
| 112 |  | 
|---|
| 113 |         /// Result of a decoding; both a decoded data stream and CodecData metadata | 
|---|
| 114 |         typedef std::pair<MemoryDataStreamPtr, CodecDataPtr> DecodeResult; | 
|---|
| 115 |         /** Codes the data from the input chunk into the output chunk. | 
|---|
| 116 |             @param input Stream containing the encoded data | 
|---|
| 117 |             @note | 
|---|
| 118 |                 Has a variable number of arguments, which depend on the codec type. | 
|---|
| 119 |         */ | 
|---|
| 120 |         virtual DecodeResult decode(DataStreamPtr& input) const = 0; | 
|---|
| 121 |  | 
|---|
| 122 |         /** Returns the type of the codec as a String | 
|---|
| 123 |         */ | 
|---|
| 124 |         virtual String getType() const = 0; | 
|---|
| 125 |  | 
|---|
| 126 |         /** Returns the type of the data that supported by this codec as a String | 
|---|
| 127 |         */ | 
|---|
| 128 |         virtual String getDataType() const = 0; | 
|---|
| 129 |     }; | 
|---|
| 130 |  | 
|---|
| 131 | } // namespace | 
|---|
| 132 |  | 
|---|
| 133 | #endif | 
|---|