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:
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 
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
OgreSharedPtr.h
OgreHeaderSuffix.h
Ogre::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::Codec::CodecData
Definition: OgreCodec.h:65
Ogre::Exception::ERR_DUPLICATE_ITEM
Definition: OgreException.h:105
Ogre::Codec::registerCodec
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition: OgreCodec.h:83
Ogre::StringVector
vector< String >::type StringVector
Definition: OgreStringVector.h:45
Ogre::Codec::CodecList
map< String, Codec * >::type CodecList
Definition: OgreCodec.h:59
Ogre::Codec::unregisterCodec
static void unregisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition: OgreCodec.h:102
OgreException.h
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::Codec::CodecData::dataType
virtual String dataType() const
Returns the type of the data.
Definition: OgreCodec.h:72
Ogre::Codec::isCodecRegistered
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition: OgreCodec.h:95
OgreHeaderPrefix.h
OgrePrerequisites.h
Ogre::Codec::CodecDataPtr
SharedPtr< CodecData > CodecDataPtr
Definition: OgreCodec.h:74
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
OgreIteratorWrappers.h
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
Ogre::Codec::magicNumberMatch
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
Returns whether a magic number header matches this codec.
Definition: OgreCodec.h:161
Ogre::Codec::getType
virtual String getType() const =0
Returns the type of the codec as a String.
Ogre::Codec::CodecData::~CodecData
virtual ~CodecData()
Definition: OgreCodec.h:68
Ogre::Codec
Abstract class that defines a 'codec'.
Definition: OgreCodec.h:56
_OgrePrivate
#define _OgrePrivate
Definition: OgrePlatform.h:258
Ogre::Codec::msMapCodecs
static CodecList msMapCodecs
A map that contains all the registered codecs.
Definition: OgreCodec.h:62
Ogre::Codec::DecodeResult
std::pair< MemoryDataStreamPtr, CodecDataPtr > DecodeResult
Result of a decoding; both a decoded data stream and CodecData metadata.
Definition: OgreCodec.h:141
Ogre::ConstMapIterator
Concrete IteratorWrapper for const access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:352
OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src)
Definition: OgreException.h:334
OgreStringVector.h
Ogre::Codec::getCodecIterator
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition: OgreCodec.h:108
Ogre::Codec::CodecIterator
ConstMapIterator< CodecList > CodecIterator
Definition: OgreCodec.h:76
OgreDataStream.h

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