- Main Page
- Classes
- Files

- Search for |

# EndianCheck.h

Go to the documentation of this file.

    00001 /*****************************
    00002 File:      EndianCheck.h
    00003 Language:   C++ (header)
    00004 Project:    H3DNetworkingUtils
    00005 The contents of this file are subject to the Mozilla Public License
    00006 Version 1.1 (the "License"); you may not use this file except in
    00007 compliance with the License. You may obtain a copy of the License at
    00008 http://www.mozilla.org/MPL/
    00009
    00010 Software distributed under the License is distributed on an "AS IS"
    00011 basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
    00012 License for the specific language governing rights and limitations
    00013 under the License.
    00014
    00015 The Original Code is H3DNetworkingUtils v1.0.
    00016
    00017 The Initial Developer of the Original Code is CSIRO.
    00018 Portions created by the Initial Developer are Copyright (C) 1009 CSIRO. All Rights Reserved.
    00019 Contributor(s):
    00020     Chris Gunn  <Chris.Gunn@csiro.au> <ChrisJGunn@gmail.com>
    00021 ***************************/
    00022
    00025
    00026
    00027 #ifndef EndianCheck_H
    00028 #define EndianCheck_H
    00029
    00030 #include "H3DNetworkingUtils/Config.h"
    00031
    00032 namespace H3DNetworkingUtils {
    00033
    00039
    00040 class H3D_NETWORKING_UTILS_DLL_SPEC EndianCheck {
    00041 public:
    00043   EndianCheck()  {
    00044     union {
    00045       short s;
    00046       char c[sizeof(short)];
    00047     } un;
    00048
    00049     un.s = 0x0102;
    00050     if (sizeof(short) == 2) {
    00051       if (un.c[0] == 2 && un.c[1] == 1) {
    00052         little_endian = true;
    00053       }
    00054       else if (un.c[0] == 1 && un.c[1] == 2) {
    00055         little_endian = false;
    00056       }
    00057     }
    00058   }
    00059
    00061   static bool isBigEndian() {return !instance.little_endian;}
    00062
    00064   static bool isLittleEndian() {return instance.little_endian;}
    00065
    00066   static EndianCheck instance;
    00067 private:
    00068   static bool little_endian;
    00069 };
    00070
    00071 }
    00072
    00073 #endif