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-2013 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 #include "OgreHeaderPrefix.h"
38 
39 namespace Ogre {
56  class _OgreExport Codec : public CodecAlloc
57  {
58  protected:
62  static CodecList msMapCodecs;
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 
108  static CodecIterator getCodecIterator(void)
109  {
110  return CodecIterator(msMapCodecs.begin(), msMapCodecs.end());
111  }
112 
114  static StringVector getExtensions(void);
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(); }
170  virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;
171  };
175 } // namespace
176 
177 #include "OgreHeaderSuffix.h"
178 
179 #endif
Abstract class that defines a &#39;codec&#39;.
Definition: OgreCodec.h:56
#define _OgreExport
Definition: OgrePlatform.h:257
SharedPtr< CodecData > CodecDataPtr
Definition: OgreCodec.h:74
Concrete IteratorWrapper for const access to the underlying key-value container.
vector< String >::type StringVector
ConstMapIterator< CodecList > CodecIterator
Definition: OgreCodec.h:76
static CodecList msMapCodecs
A map that contains all the registered codecs.
Definition: OgreCodec.h:62
std::map< K, V, P, A > type
#define _OgrePrivate
Definition: OgrePlatform.h:258
_StringBase String
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
Returns whether a magic number header matches this codec.
Definition: OgreCodec.h:161
map< String, Codec * >::type CodecList
Definition: OgreCodec.h:59
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition: OgreCodec.h:83
virtual String getType() const =0
Returns the type of the codec as a String.
virtual String dataType() const
Returns the type of the data.
Definition: OgreCodec.h:72
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition: OgreCodec.h:95
#define OGRE_EXCEPT(num, desc, src)
static void unregisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition: OgreCodec.h:102
virtual ~CodecData()
Definition: OgreCodec.h:68
Reference-counted shared pointer, used for objects where implicit destruction is required.
std::pair< MemoryDataStreamPtr, CodecDataPtr > DecodeResult
Result of a decoding; both a decoded data stream and CodecData metadata.
Definition: OgreCodec.h:141
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition: OgreCodec.h:108

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.