OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OgreCodec.h
Go to the documentation of this file.
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-2011 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 "OgreSharedPtr.h"
33 #include "OgreDataStream.h"
34 #include "OgreIteratorWrappers.h"
35 #include "OgreStringVector.h"
36 #include "OgreException.h"
37 
38 namespace Ogre {
55  class _OgreExport Codec : public CodecAlloc
56  {
57  protected:
62 
63  public:
65  {
66  public:
67  virtual ~CodecData() {}
68 
71  virtual String dataType() const { return "CodecData"; }
72  };
74 
76 
77  public:
78  virtual ~Codec();
79 
82  static void registerCodec( Codec *pCodec )
83  {
84  CodecList::iterator i = ms_mapCodecs.find(pCodec->getType());
85  if (i != ms_mapCodecs.end())
87  pCodec->getType() + " already has a registered codec. ", __FUNCTION__);
88 
89  ms_mapCodecs[pCodec->getType()] = pCodec;
90  }
91 
94  static bool isCodecRegistered( const String& codecType )
95  {
96  return ms_mapCodecs.find(codecType) != ms_mapCodecs.end();
97  }
98 
101  static void unRegisterCodec( Codec *pCodec )
102  {
103  ms_mapCodecs.erase(pCodec->getType());
104  }
105 
108  {
109  return CodecIterator(ms_mapCodecs.begin(), ms_mapCodecs.end());
110  }
111 
113  static StringVector getExtensions(void);
114 
116  static Codec* getCodec(const String& extension);
117 
124  static Codec* getCodec(char *magicNumberPtr, size_t maxbytes);
125 
129  virtual DataStreamPtr code(MemoryDataStreamPtr& input, CodecDataPtr& pData) const = 0;
137  virtual void codeToFile(MemoryDataStreamPtr& input, const String& outFileName, CodecDataPtr& pData) const = 0;
138 
140  typedef std::pair<MemoryDataStreamPtr, CodecDataPtr> DecodeResult;
146  virtual DecodeResult decode(DataStreamPtr& input) const = 0;
147 
150  virtual String getType() const = 0;
151 
154  virtual String getDataType() const = 0;
155 
162  virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
163  { return !magicNumberToFileExt(magicNumberPtr, maxbytes).empty(); }
171  virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;
172  };
176 } // namespace
177 
178 #endif
Abstract class that defines a 'codec'.
Definition: OgreCodec.h:55
#define _OgreExport
Definition: OgrePlatform.h:203
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition: OgreCodec.h:107
virtual String dataType() const
Returns the type of the data.
Definition: OgreCodec.h:71
static CodecList ms_mapCodecs
A map that contains all the registered codecs.
Definition: OgreCodec.h:61
SharedPtr< CodecData > CodecDataPtr
Definition: OgreCodec.h:73
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
Returns whether a magic number header matches this codec.
Definition: OgreCodec.h:162
static void unRegisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition: OgreCodec.h:101
map< String, Codec * >::type CodecList
Definition: OgreCodec.h:58
#define _OgrePrivate
Definition: OgrePlatform.h:204
#define OGRE_EXCEPT(num, desc, src)
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
vector< String >::type StringVector
ConstMapIterator< CodecList > CodecIterator
Definition: OgreCodec.h:75
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition: OgreCodec.h:82
std::map< K, V, P, A > type
std::pair< MemoryDataStreamPtr, CodecDataPtr > DecodeResult
Result of a decoding; both a decoded data stream and CodecData metadata.
Definition: OgreCodec.h:140
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition: OgreCodec.h:94
Concrete IteratorWrapper for const access to the underlying key-value container.
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgreSharedPtr.h:60
_StringBase String
virtual String getType() const =0
Returns the type of the codec as a String.
virtual ~CodecData()
Definition: OgreCodec.h:67