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

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Wed Oct 23 2013 06:57:23