Main Page | User's Guide | Namespace List | Class List | File List | Namespace Members | Class Members

Common.hxx

00001 // Copyright (C) 2003-2005 CEREA
00002 //     Author: Vivien Mallet
00003 //
00004 // CEREA (http://www.enpc.fr/cerea) is a joint laboratory of
00005 // ENPC (http://www.enpc.fr) and EDF R&D (http://www.edf.fr).
00006 //
00007 // This file is part of AtmoData library.
00008 // AtmoData library is a tool for data processing in atmospheric
00009 // sciences.
00010 // 
00011 // AtmoData is free software; you can redistribute it and/or modify
00012 // it under the terms of the GNU General Public License as published by
00013 // the Free Software Foundation; either version 2 of the License, or
00014 // (at your option) any later version.
00015 // 
00016 // AtmoData is distributed in the hope that it will be useful,
00017 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 // GNU General Public License (file "license") for more details.
00020 //
00021 // For more information, please see the AtmoData home page:
00022 //     http://spacetown.free.fr/lib/atmodata
00023 
00024 
00025 #ifndef ATMODATA_FILE_COMMON_HXX
00026 
00027 namespace AtmoData
00028 {
00029 
00030 #define SWAP_4(a) ((a >> 24) & 0xFF) | ((a >> 8) & 0xFF00) | \
00031       ((a << 8) & 0x00FF0000) | ((a << 24) & 0xFF000000)
00032   
00033   inline float swap(float& x)
00034   {
00035     return (*(unsigned *)&x = SWAP_4(*(unsigned *)&x));
00036   }
00037   
00038   inline int swap(int& x)
00039   {
00040     return (*(unsigned *)&x = SWAP_4(*(unsigned *)&x));
00041   }
00042   
00043   inline unsigned long swap(unsigned long& x)
00044   {
00045     return (*(unsigned *)&x = SWAP_4(*(unsigned *)&x));
00046   }
00047   
00048   template <class T, int N>
00049   inline void swap(Array<T, N>& A)
00050   {
00051     for (int i=0; i<A.size(); i++)
00052       swap(A.data()[i]);
00053   }
00054   
00055 }  // namespace AtmoData.
00056 
00057 
00058 #define ATMODATA_FILE_COMMON_HXX
00059 #endif

Generated on Tue Nov 7 14:58:48 2006 for AtmoData by  doxygen 1.4.2