/src/ogre/OgreMain/include/OgreCodec.h
Line | Count | Source |
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-2014 Torus Knot Software Ltd |
8 | | |
9 | | Permission is hereby granted, free of charge, to any person obtaining a copy |
10 | | of this software and associated documentation files (the "Software"), to deal |
11 | | in the Software without restriction, including without limitation the rights |
12 | | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13 | | copies of the Software, and to permit persons to whom the Software is |
14 | | furnished to do so, subject to the following conditions: |
15 | | |
16 | | The above copyright notice and this permission notice shall be included in |
17 | | all copies or substantial portions of the Software. |
18 | | |
19 | | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20 | | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21 | | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22 | | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23 | | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24 | | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
25 | | THE SOFTWARE. |
26 | | ----------------------------------------------------------------------------- |
27 | | */ |
28 | | #ifndef _Codec_H__ |
29 | | #define _Codec_H__ |
30 | | |
31 | | #include "OgrePrerequisites.h" |
32 | | #include "OgreIteratorWrapper.h" |
33 | | #include "OgreStringVector.h" |
34 | | #include "OgreException.h" |
35 | | #include "OgreHeaderPrefix.h" |
36 | | #include "OgreAny.h" |
37 | | |
38 | | namespace Ogre { |
39 | | /** \addtogroup Core |
40 | | * @{ |
41 | | */ |
42 | | /** \addtogroup General |
43 | | * @{ |
44 | | */ |
45 | | |
46 | | /** Abstract class that defines a 'codec'. |
47 | | |
48 | | A codec class works like a two-way filter for data - data entered on |
49 | | one end (the decode end) gets processed and transformed into easily |
50 | | usable data while data passed the other way around codes it back. |
51 | | @par |
52 | | The codec concept is a pretty generic one - you can easily understand |
53 | | how it can be used for images, sounds, archives, even compressed data. |
54 | | */ |
55 | | class _OgreExport Codec : public CodecAlloc |
56 | | { |
57 | | private: |
58 | | typedef std::map< String, Codec* > CodecList; |
59 | | /** A map that contains all the registered codecs. |
60 | | */ |
61 | | static CodecList msMapCodecs; |
62 | | |
63 | | public: |
64 | | virtual ~Codec(); |
65 | | |
66 | | /** Registers a new codec in the database. |
67 | | */ |
68 | | static void registerCodec( Codec *pCodec ); |
69 | | |
70 | | /** Return whether a codec is registered already. |
71 | | */ |
72 | | static bool isCodecRegistered( const String& codecType ) |
73 | 0 | { |
74 | 0 | return msMapCodecs.find(codecType) != msMapCodecs.end(); |
75 | 0 | } |
76 | | |
77 | | /** Unregisters a codec from the database. |
78 | | */ |
79 | | static void unregisterCodec( Codec *pCodec ) |
80 | 36.1k | { |
81 | 36.1k | msMapCodecs.erase(pCodec->getType()); |
82 | 36.1k | } |
83 | | |
84 | | /** Gets the file extension list for the registered codecs. */ |
85 | | static StringVector getExtensions(void); |
86 | | |
87 | | /** Gets the codec registered for the passed in file extension. */ |
88 | | static Codec* getCodec(const String& extension); |
89 | | |
90 | | /** Gets the codec that can handle the given 'magic' identifier. |
91 | | @param magicNumberPtr Pointer to a stream of bytes which should identify the file. |
92 | | Note that this may be more than needed - each codec may be looking for |
93 | | a different size magic number. |
94 | | @param maxbytes The number of bytes passed |
95 | | */ |
96 | | static Codec* getCodec(char *magicNumberPtr, size_t maxbytes); |
97 | | |
98 | | /** Codes the input and saves the result in the output |
99 | | stream. |
100 | | */ |
101 | | virtual DataStreamPtr encode(const Any& input) const; |
102 | | |
103 | | /** Codes the data in the input chunk and saves the result in the output |
104 | | filename provided. Provided for efficiency since coding to memory is |
105 | | progressive therefore memory required is unknown leading to reallocations. |
106 | | @param input The input data (codec type specific) |
107 | | @param outFileName The filename to write to |
108 | | */ |
109 | | virtual void encodeToFile(const Any& input, const String& outFileName) const; |
110 | | |
111 | | /** Codes the data from the input chunk into the output chunk. |
112 | | @param input Stream containing the encoded data |
113 | | @param output codec type specific result |
114 | | */ |
115 | | virtual void decode(const DataStreamPtr& input, const Any& output) const = 0; |
116 | | |
117 | | /** Returns the type of the codec as a String |
118 | | */ |
119 | | virtual String getType() const = 0; |
120 | | |
121 | | /** Returns whether a magic number header matches this codec. |
122 | | @param magicNumberPtr Pointer to a stream of bytes which should identify the file. |
123 | | Note that this may be more than needed - each codec may be looking for |
124 | | a different size magic number. |
125 | | @param maxbytes The number of bytes passed |
126 | | */ |
127 | | bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const |
128 | 0 | { return !magicNumberToFileExt(magicNumberPtr, maxbytes).empty(); } |
129 | | /** Maps a magic number header to a file extension, if this codec recognises it. |
130 | | @param magicNumberPtr Pointer to a stream of bytes which should identify the file. |
131 | | Note that this may be more than needed - each codec may be looking for |
132 | | a different size magic number. |
133 | | @param maxbytes The number of bytes passed |
134 | | @return A blank string if the magic number was unknown, or a file extension. |
135 | | */ |
136 | | virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0; |
137 | | |
138 | 0 | virtual bool setParameter(const String& name, const String& value) { return false; } |
139 | | }; |
140 | | /** @} */ |
141 | | /** @} */ |
142 | | |
143 | | } // namespace |
144 | | |
145 | | #include "OgreHeaderSuffix.h" |
146 | | |
147 | | #endif |