OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties 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-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 "OgreIteratorWrappers.h"
33 #include "OgreStringVector.h"
34 #include "OgreException.h"
35 #include "OgreHeaderPrefix.h"
36 
37 namespace Ogre {
54  class _OgreExport Codec : public CodecAlloc
55  {
56  protected:
61 
62  public:
64  {
65  public:
66  virtual ~CodecData() {}
67 
70  virtual String dataType() const { return "CodecData"; }
71  };
73 
75 
76  public:
77  virtual ~Codec();
78 
81  static void registerCodec( Codec *pCodec )
82  {
83  CodecList::iterator i = msMapCodecs.find(pCodec->getType());
84  if (i != msMapCodecs.end())
86  pCodec->getType() + " already has a registered codec. ", __FUNCTION__);
87 
88  msMapCodecs[pCodec->getType()] = pCodec;
89  }
90 
93  static bool isCodecRegistered( const String& codecType )
94  {
95  return msMapCodecs.find(codecType) != msMapCodecs.end();
96  }
97 
100  static void unregisterCodec( Codec *pCodec )
101  {
102  msMapCodecs.erase(pCodec->getType());
103  }
104 
107  {
108  return CodecIterator(msMapCodecs.begin(), msMapCodecs.end());
109  }
110 
112  static StringVector getExtensions(void);
113 
115  static Codec* getCodec(const String& extension);
116 
123  static Codec* getCodec(char *magicNumberPtr, size_t maxbytes);
124 
128  virtual DataStreamPtr encode(MemoryDataStreamPtr& input, CodecDataPtr& pData) const = 0;
136  virtual void encodeToFile(MemoryDataStreamPtr& input, const String& outFileName, CodecDataPtr& pData) const = 0;
137 
139  typedef std::pair<MemoryDataStreamPtr, CodecDataPtr> DecodeResult;
143  virtual DecodeResult decode(DataStreamPtr& input) const = 0;
144 
147  virtual String getType() const = 0;
148 
151  virtual String getDataType() const = 0;
152 
159  virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
160  { return !magicNumberToFileExt(magicNumberPtr, maxbytes).empty(); }
168  virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;
169  };
173 } // namespace
174 
175 #include "OgreHeaderSuffix.h"
176 
177 #endif
Abstract class that defines a 'codec'.
Definition: OgreCodec.h:54
#define _OgreExport
Definition: OgrePlatform.h:255
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition: OgreCodec.h:106
static CodecList msMapCodecs
A map that contains all the registered codecs.
Definition: OgreCodec.h:60
virtual String dataType() const
Returns the type of the data.
Definition: OgreCodec.h:70
SharedPtr< CodecData > CodecDataPtr
Definition: OgreCodec.h:72
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
Returns whether a magic number header matches this codec.
Definition: OgreCodec.h:159
map< String, Codec * >::type CodecList
Definition: OgreCodec.h:57
#define _OgrePrivate
Definition: OgrePlatform.h:256
#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:74
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition: OgreCodec.h:81
std::map< K, V, P, A > type
static void unregisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition: OgreCodec.h:100
std::pair< MemoryDataStreamPtr, CodecDataPtr > DecodeResult
Result of a decoding; both a decoded data stream and CodecData metadata.
Definition: OgreCodec.h:139
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition: OgreCodec.h:93
Concrete IteratorWrapper for const access to the underlying key-value container.
Reference-counted shared pointer, used for objects where implicit destruction is required.
_StringBase String
Definition: OgreCommon.h:53
virtual String getType() const =0
Returns the type of the codec as a String.
virtual ~CodecData()
Definition: OgreCodec.h:66