source: GTP/trunk/Lib/Geom/OgreStuff/include/OgreCodec.h @ 1809

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