OGRE  1.9.0
OgreCodec.h
Go to the documentation of this file.
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-2014 Torus Knot Software Ltd
8
9Permission is hereby granted, free of charge, to any person obtaining a copy
10of this software and associated documentation files (the "Software"), to deal
11in the Software without restriction, including without limitation the rights
12to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13copies of the Software, and to permit persons to whom the Software is
14furnished to do so, subject to the following conditions:
15
16The above copyright notice and this permission notice shall be included in
17all copies or substantial portions of the Software.
18
19THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25THE SOFTWARE.
26-----------------------------------------------------------------------------
27*/
28#ifndef _Codec_H__
29#define _Codec_H__
30
31#include "OgrePrerequisites.h"
32#include "OgreSharedPtr.h"
33#include "OgreDataStream.h"
35#include "OgreStringVector.h"
36#include "OgreException.h"
37#include "OgreHeaderPrefix.h"
38
39namespace Ogre {
46
57 {
58 protected:
63
64 public:
66 {
67 public:
68 virtual ~CodecData() {}
69
72 virtual String dataType() const { return "CodecData"; }
73 };
75
77
78 public:
79 virtual ~Codec();
80
83 static void registerCodec( Codec *pCodec )
84 {
85 CodecList::iterator i = msMapCodecs.find(pCodec->getType());
86 if (i != msMapCodecs.end())
88 pCodec->getType() + " already has a registered codec. ", __FUNCTION__);
89
90 msMapCodecs[pCodec->getType()] = pCodec;
91 }
92
95 static bool isCodecRegistered( const String& codecType )
96 {
97 return msMapCodecs.find(codecType) != msMapCodecs.end();
98 }
99
102 static void unregisterCodec( Codec *pCodec )
103 {
104 msMapCodecs.erase(pCodec->getType());
105 }
106
109 {
110 return CodecIterator(msMapCodecs.begin(), msMapCodecs.end());
111 }
112
115
117 static Codec* getCodec(const String& extension);
118
125 static Codec* getCodec(char *magicNumberPtr, size_t maxbytes);
126
130 virtual DataStreamPtr encode(MemoryDataStreamPtr& input, CodecDataPtr& pData) const = 0;
138 virtual void encodeToFile(MemoryDataStreamPtr& input, const String& outFileName, CodecDataPtr& pData) const = 0;
139
141 typedef std::pair<MemoryDataStreamPtr, CodecDataPtr> DecodeResult;
145 virtual DecodeResult decode(DataStreamPtr& input) const = 0;
146
149 virtual String getType() const = 0;
150
153 virtual String getDataType() const = 0;
154
161 virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
162 { return !magicNumberToFileExt(magicNumberPtr, maxbytes).empty(); }
163
170 virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;
171 };
172
174
175} // namespace
176
177#include "OgreHeaderSuffix.h"
178
179#endif
#define _OgreExport
#define _OgrePrivate
virtual String dataType() const
Returns the type of the data.
Definition OgreCodec.h:72
Abstract class that defines a 'codec'.
Definition OgreCodec.h:57
ConstMapIterator< CodecList > CodecIterator
Definition OgreCodec.h:76
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
Returns whether a magic number header matches this codec.
Definition OgreCodec.h:161
SharedPtr< CodecData > CodecDataPtr
Definition OgreCodec.h:74
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition OgreCodec.h:108
static StringVector getExtensions(void)
Gets the file extension list for the registered codecs.
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition OgreCodec.h:83
virtual DecodeResult decode(DataStreamPtr &input) const =0
Codes the data from the input chunk into the output chunk.
static CodecList msMapCodecs
A map that contains all the registered codecs.
Definition OgreCodec.h:62
static void unregisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition OgreCodec.h:102
map< String, Codec * >::type CodecList
Definition OgreCodec.h:59
std::pair< MemoryDataStreamPtr, CodecDataPtr > DecodeResult
Result of a decoding; both a decoded data stream and CodecData metadata.
Definition OgreCodec.h:141
static Codec * getCodec(char *magicNumberPtr, size_t maxbytes)
Gets the codec that can handle the given 'magic' identifier.
virtual void encodeToFile(MemoryDataStreamPtr &input, const String &outFileName, CodecDataPtr &pData) const =0
Codes the data in the input chunk and saves the result in the output filename provided.
virtual DataStreamPtr encode(MemoryDataStreamPtr &input, CodecDataPtr &pData) const =0
Codes the data in the input stream and saves the result in the output stream.
virtual String getType() const =0
Returns the type of the codec as a String.
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition OgreCodec.h:95
virtual String getDataType() const =0
Returns the type of the data that supported by this codec as a String.
static Codec * getCodec(const String &extension)
Gets the codec registered for the passed in file extension.
virtual ~Codec()
virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const =0
Maps a magic number header to a file extension, if this codec recognises it.
Concrete IteratorWrapper for const access to the underlying key-value container.
Reference-counted shared pointer, used for objects where implicit destruction is required.
vector< String >::type StringVector
#define OGRE_EXCEPT(code, desc, src)
SharedPtr< DataStream > DataStreamPtr
Shared pointer to allow data streams to be passed around without worrying about deallocation.
SharedPtr< MemoryDataStream > MemoryDataStreamPtr
Shared pointer to allow memory data streams to be passed around without worrying about deallocation.
GeneralAllocatedObject CodecAlloc
_StringBase String
std::map< K, V, P, A > type