PageRenderTime 18ms CodeModel.GetById 8ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/Rainman2/binaryattrib.h

http://modstudio2.googlecode.com/
C++ Header | 51 lines | 12 code | 2 blank | 37 comment | 0 complexity | 56a7e84440d2acbbab7bf01f3915cee7 MD5 | raw file
 1/*
 2Copyright (c) 2008 Peter "Corsix" Cawley
 3
 4Permission is hereby granted, free of charge, to any person
 5obtaining a copy of this software and associated documentation
 6files (the "Software"), to deal in the Software without
 7restriction, including without limitation the rights to use,
 8copy, modify, merge, publish, distribute, sublicense, and/or sell
 9copies of the Software, and to permit persons to whom the
10Software is furnished to do so, subject to the following
11conditions:
12
13The above copyright notice and this permission notice shall be
14included in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23OTHER DEALINGS IN THE SOFTWARE.
24*/
25#pragma once
26#include "attributes.h"
27
28//! Semantic method for linking types and their equivalent codes in binary attrib files
29/*!
30  All types which can be found in binary attrib files have a code associated with them,
31  which usually precedes the actual value. Having these codes done in this form allows
32  for things like BinaryAttribDataTypeCode<char*>::code to be placed into source files,
33  rather than the meaningless `3`.
34*/
35template <class T> struct BinaryAttribDataTypeCode {};
36template <> struct BinaryAttribDataTypeCode<float>           {static const long code =   0;};
37template <> struct BinaryAttribDataTypeCode<long>            {static const long code =   1;};
38template <> struct BinaryAttribDataTypeCode<bool>            {static const long code =   2;};
39template <> struct BinaryAttribDataTypeCode<char*>           {static const long code =   3;};
40template <> struct BinaryAttribDataTypeCode<wchar_t*>        {static const long code =   4;};
41template <> struct BinaryAttribDataTypeCode<IAttributeTable> {static const long code = 100;};
42
43//! Semantic method for converting between boolean values and their encoded form in binary attrib files
44/*!
45  true and false are represented by a single byte 1 and 0 respectively. Having this
46  information in the form below allows things like BinaryAttribBooleanEncoding<true>::value
47  to be placed into source files, rather than the ambiguous `1`.
48*/
49template <bool b> struct BinaryAttribBooleanEncoding {};
50template <> struct BinaryAttribBooleanEncoding<true>  {static const unsigned char value = 1;};
51template <> struct BinaryAttribBooleanEncoding<false> {static const unsigned char value = 0;};