Common.hxx

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

Generated on Tue Nov 17 11:51:45 2009 for AtmoData by  doxygen 1.5.1