OgreCodec.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef _Codec_H__
#define _Codec_H__
#include "OgrePrerequisites.h"
#include "OgreSharedPtr.h"
#include "OgreDataStream.h"
#include "OgreIteratorWrappers.h"
#include "OgreStringVector.h"
#include "OgreException.h"
#include "OgreHeaderPrefix.h"
namespace Ogre {
class _OgreExport Codec : public CodecAlloc
{
protected:
typedef map< String, Codec* >::type CodecList;
static CodecList msMapCodecs;
public:
class _OgrePrivate CodecData : public CodecAlloc
{
public:
virtual ~CodecData() {}
virtual String dataType() const { return "CodecData"; }
};
typedef SharedPtr<CodecData> CodecDataPtr;
typedef ConstMapIterator<CodecList> CodecIterator;
public:
virtual ~Codec();
static void registerCodec( Codec *pCodec )
{
CodecList::iterator i = msMapCodecs.find(pCodec->getType());
if (i != msMapCodecs.end())
OGRE_EXCEPT(Exception::ERR_DUPLICATE_ITEM,
pCodec->getType() + " already has a registered codec. ", __FUNCTION__);
msMapCodecs[pCodec->getType()] = pCodec;
}
static bool isCodecRegistered( const String& codecType )
{
return msMapCodecs.find(codecType) != msMapCodecs.end();
}
static void unregisterCodec( Codec *pCodec )
{
msMapCodecs.erase(pCodec->getType());
}
static CodecIterator getCodecIterator(void)
{
return CodecIterator(msMapCodecs.begin(), msMapCodecs.end());
}
static StringVector getExtensions(void);
static Codec* getCodec(const String& extension);
static Codec* getCodec(char *magicNumberPtr, size_t maxbytes);
virtual DataStreamPtr encode(MemoryDataStreamPtr& input, CodecDataPtr& pData) const = 0;
virtual void encodeToFile(MemoryDataStreamPtr& input, const String& outFileName, CodecDataPtr& pData) const = 0;
typedef std::pair<MemoryDataStreamPtr, CodecDataPtr> DecodeResult;
virtual DecodeResult decode(DataStreamPtr& input) const = 0;
virtual String getType() const = 0;
virtual String getDataType() const = 0;
virtual bool magicNumberMatch(const char *magicNumberPtr, size_t maxbytes) const
{ return !magicNumberToFileExt(magicNumberPtr, maxbytes).empty(); }
virtual String magicNumberToFileExt(const char *magicNumberPtr, size_t maxbytes) const = 0;
};
} // namespace
#include "OgreHeaderSuffix.h"
#endif
Ogre::Codec
Abstract class that defines a &#39;codec&#39;.
Definition: OgreCodec.h:56
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
OgreSharedPtr.h
Ogre::Codec::CodecDataPtr
SharedPtr< CodecData > CodecDataPtr
Definition: OgreCodec.h:74
Ogre::ConstMapIterator
Concrete IteratorWrapper for const access to the underlying key-value container.
Definition: OgreIteratorWrapper.h:352
Ogre::StringVector
vector< String >::type StringVector
Definition: OgreStringVector.h:45
Ogre::Codec::CodecIterator
ConstMapIterator< CodecList > CodecIterator
Definition: OgreCodec.h:76
Ogre::Codec::msMapCodecs
static CodecList msMapCodecs
A map that contains all the registered codecs.
Definition: OgreCodec.h:62
OgreDataStream.h
Ogre::Codec::CodecData::dataType
virtual String dataType() const
Returns the type of the data.
Definition: OgreCodec.h:72
Ogre::Exception::ERR_DUPLICATE_ITEM
Definition: OgreException.h:105
OgrePrerequisites.h
Ogre::map::type
std::map< K, V, P, A > type
Definition: OgrePrerequisites.h:536
_OgrePrivate
#define _OgrePrivate
Definition: OgrePlatform.h:258
OgreStringVector.h
Ogre::Codec::CodecData
Definition: OgreCodec.h:65
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
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::CodecList
map< String, Codec *>::type CodecList
Definition: OgreCodec.h:59
Ogre::Codec::registerCodec
static void registerCodec(Codec *pCodec)
Registers a new codec in the database.
Definition: OgreCodec.h:83
OgreHeaderSuffix.h
Ogre::Codec::getType
virtual String getType() const =0
Returns the type of the codec as a String.
Ogre::Codec::isCodecRegistered
static bool isCodecRegistered(const String &codecType)
Return whether a codec is registered already.
Definition: OgreCodec.h:95
OgreIteratorWrappers.h
OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src)
Definition: OgreException.h:334
Ogre::Codec::unregisterCodec
static void unregisterCodec(Codec *pCodec)
Unregisters a codec from the database.
Definition: OgreCodec.h:102
Ogre
Definition: OgreAndroidLogListener.h:34
OgreException.h
Ogre::Codec::CodecData::~CodecData
virtual ~CodecData()
Definition: OgreCodec.h:68
Ogre::SharedPtr
Reference-counted shared pointer, used for objects where implicit destruction is required.
Definition: OgrePrerequisites.h:310
OgreHeaderPrefix.h
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::AllocatedObject
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Definition: OgreMemoryAllocatedObject.h:58
Ogre::Codec::getCodecIterator
static CodecIterator getCodecIterator(void)
Gets the iterator for the registered codecs.
Definition: OgreCodec.h:108

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