Ticket #22: BaseFunctions_ByteOrder.diff

File BaseFunctions_ByteOrder.diff, 26.3 kB (added by cneumann, 2 years ago)

patch

  • Source/Base/Base/OSGBaseFunctions.h

    old new  
    256256inline 
    257257bool osgIsBigEndian(void); 
    258258 
     259// The osgHostTo??? and osg???ToHost templates are NOT implemented, there are 
     260// only overloads for some types available, these are: 
     261// UInt16, UInt32, UInt64, Real32, Real64, Real128 
     262 
     263template <class TypeT> 
     264TypeT osgHostToBigEndian(TypeT src); 
     265 
     266template <class TypeT> 
     267TypeT osgHostToLittleEndian(TypeT src); 
     268 
     269template <class TypeT> 
     270TypeT osgBigEndianToHost(TypeT src); 
     271 
     272template <class TypeT> 
     273TypeT osgLittleEndianToHost(TypeT src); 
     274 
    259275// host to network 
    260276 
    261277inline 
    262 UInt16 osghtons (UInt16  src); 
     278UInt16 osghtons (UInt16  src); 
    263279 
    264280inline 
    265 UInt32 osghtonl (UInt32  src); 
     281UInt32 osghtonl (UInt32  src); 
    266282 
    267283inline 
    268 UInt64 osghtonll (UInt64  src); 
     284UInt64 osghtonll(UInt64  src); 
    269285 
    270286inline 
    271 Real32 osghtonf (Real32  src); 
     287Real32 osghtonf (Real32  src); 
    272288 
    273289inline 
    274 Real64 osghtond (Real64  src); 
     290Real64 osghtond (Real64  src); 
    275291 
    276292inline 
    277293Real128 osghtondd(Real128 src); 
     
    279295// network to host 
    280296 
    281297inline 
    282 UInt16 osgntohs (UInt16  src); 
     298UInt16 osgntohs (UInt16  src); 
    283299 
    284300inline 
    285 UInt32 osgntohl (UInt32  src); 
     301UInt32 osgntohl (UInt32  src); 
    286302 
    287303inline 
    288 UInt64 osgntohll(UInt64  src); 
     304UInt64 osgntohll(UInt64  src); 
    289305 
    290306inline 
    291 Real32 osgntohf (Real32  src); 
     307Real32 osgntohf (Real32  src); 
    292308 
    293309inline 
    294 Real64 osgntohd (Real64  src); 
     310Real64 osgntohd (Real64  src); 
    295311 
    296312inline 
    297 Real128 osgntohd(Real128 src); 
     313Real128 osgntohdd(Real128 src); 
    298314 
    299315/*---------------------------------------------------------------------*/ 
    300316/*                   Case String Runtime Functions                     */ 
  • Source/Base/Base/OSGBaseFunctions.inl

    old new  
    15751575    return (BYTE_ORDER) == (BIG_ENDIAN); 
    15761576} 
    15771577 
     1578/*! Convert a UInt16 from host byte order to big endian byte order. 
     1579 
     1580    \param[in] src Input value in host byte order. 
     1581    \return The input converted to big endian byte order. 
     1582 
     1583    \note An actual conversion only happens on little endian architectures. 
     1584 
     1585    \ingroup GrpBaseBaseMiscFn 
     1586 */ 
     1587inline 
     1588UInt16 osgHostToBigEndian(UInt16 src) 
     1589{ 
    15781590#if BYTE_ORDER == LITTLE_ENDIAN 
     1591    return (src >> 8) | (src << 8); 
     1592#else 
     1593    return src; 
     1594#endif 
     1595} 
    15791596 
    1580 // host to network 
     1597/*! Convert a UInt16 from host byte order to little endian byte order. 
    15811598 
    1582 /*! Convert a UInt16 from host byte order to network byte order. 
    1583  
    15841599    \param[in] src Input value in host byte order. 
    1585     \return The input converted to network byte order. 
     1600    \return The input converted to little endian byte order. 
    15861601 
    1587     \note Network byte order is big endian, so an actual conversion only 
    1588     happens on little endian architectures. 
     1602    \note An actual conversion only happens on big endian architectures. 
    15891603 
    15901604    \ingroup GrpBaseBaseMiscFn 
    15911605 */ 
    15921606inline 
    1593 UInt16 osghtons(UInt16 src) 
     1607UInt16 osgHostToLittleEndian(UInt16 src) 
    15941608{ 
     1609#if BYTE_ORDER == LITTLE_ENDIAN 
     1610    return src; 
     1611#else 
    15951612    return (src >> 8) | (src << 8); 
     1613#endif 
    15961614} 
    15971615 
    1598 /*! Convert a UInt32 from host byte order to network byte order. 
     1616/*! Convert a UInt16 from big endian byte order to host byte order. 
    15991617 
    1600     \param[in] src Input value in host byte order. 
    1601     \return The input converted to network byte order. 
     1618    \param[in] src Input value in big endian byte order. 
     1619    \return The input converted to host byte order. 
    16021620 
    1603     \note Network byte order is big endian, so an actual conversion only 
    1604     happens on little endian architectures. 
     1621    \note An actual conversion only happens on little endian architectures. 
    16051622 
    16061623    \ingroup GrpBaseBaseMiscFn 
    16071624 */ 
    16081625inline 
    1609 UInt32 osghtonl(UInt32 src) 
     1626UInt16 osgBigEndianToHost(UInt16 src) 
    16101627{ 
    1611     return ((src&0x000000ff) << 24) | 
    1612            ((src&0x0000ff00) << 8 ) | 
    1613            ((src&0x00ff0000) >> 8 ) | 
    1614            ((src&0xff000000) >> 24); 
     1628#if BYTE_ORDER == LITTLE_ENDIAN 
     1629    return (src >> 8) | (src << 8); 
     1630#else 
     1631    return src; 
     1632#endif 
    16151633} 
    16161634 
    1617 /*! Convert a UInt64 from host byte order to network byte order. 
     1635/*! Convert a UInt16 from little endian byte order to host byte order. 
    16181636 
     1637    \param[in] src Input value in little endian byte order. 
     1638    \return The input converted to host byte order. 
     1639 
     1640    \note An actual conversion only happens on big endian architectures. 
     1641 
     1642    \ingroup GrpBaseBaseMiscFn 
     1643 */ 
     1644inline  
     1645UInt16 osgLittleEndianToHost(UInt16 src) 
     1646{ 
     1647#if BYTE_ORDER == LITTLE_ENDIAN 
     1648    return src; 
     1649#else 
     1650    return (src >> 8) | (src << 8); 
     1651#endif 
     1652} 
     1653 
     1654/*! Convert a UInt32 from host byte order to big endian byte order. 
     1655 
    16191656    \param[in] src Input value in host byte order. 
    1620     \return The input converted to network byte order. 
     1657    \return The input converted to big endian byte order. 
    16211658 
    1622     \note Network byte order is big endian, so an actual conversion only 
    1623     happens on little endian architectures. 
     1659    \note An actual conversion only happens on little endian architectures. 
    16241660 
    16251661    \ingroup GrpBaseBaseMiscFn 
    16261662 */ 
    16271663inline 
    1628 UInt64 osghtonll(UInt64 src) 
     1664UInt32 osgHostToBigEndian(UInt32 src) 
    16291665{ 
    1630 #ifdef OSG_LONGLONG_HAS_LL 
    1631     return ((src&0x00000000000000ffLL) << 56) | 
    1632            ((src&0x000000000000ff00LL) << 40) | 
    1633            ((src&0x0000000000ff0000LL) << 24) | 
    1634            ((src&0x00000000ff000000LL) << 8 ) | 
    1635            ((src&0x000000ff00000000LL) >> 8 ) | 
    1636            ((src&0x0000ff0000000000LL) >> 24) | 
    1637            ((src&0x00ff000000000000LL) >> 40) | 
    1638            ((src&0xff00000000000000LL) >> 56); 
     1666#if BYTE_ORDER == LITTLE_ENDIAN 
     1667    return ((src & 0x000000ff) << 24) | 
     1668           ((src & 0x0000ff00) << 8 ) | 
     1669           ((src & 0x00ff0000) >> 8 ) | 
     1670           ((src & 0xff000000) >> 24); 
    16391671#else 
    1640     return ((src&0x00000000000000ff) << 56) | 
    1641            ((src&0x000000000000ff00) << 40) | 
    1642            ((src&0x0000000000ff0000) << 24) | 
    1643            ((src&0x00000000ff000000) << 8 ) | 
    1644            ((src&0x000000ff00000000) >> 8 ) | 
    1645            ((src&0x0000ff0000000000) >> 24) | 
    1646            ((src&0x00ff000000000000) >> 40) | 
    1647            ((src&0xff00000000000000) >> 56); 
     1672    return src; 
    16481673#endif 
    16491674} 
    16501675 
    1651 /*! Convert a Real32 from host byte order to network byte order. 
     1676/*! Convert a UInt32 from host byte order to little endian byte order. 
    16521677 
    16531678    \param[in] src Input value in host byte order. 
    1654     \return The input converted to network byte order. 
     1679    \return The input converted to little endian byte order. 
    16551680 
    1656     \note Network byte order is big endian, so an actual conversion only 
    1657     happens on little endian architectures. 
     1681    \note An actual conversion only happens on big endian architectures. 
    16581682 
    16591683    \ingroup GrpBaseBaseMiscFn 
    16601684 */ 
    16611685inline 
    1662 Real32 osghtonf(Real32 src) 
     1686UInt32 osgHostToLittleEndian(UInt32 src) 
    16631687{ 
    1664     UInt8 *p = (UInt8 *) &src; 
     1688#if BYTE_ORDER == LITTLE_ENDIAN 
     1689    return src; 
     1690#else 
     1691    return ((src & 0x000000ff) << 24) | 
     1692           ((src & 0x0000ff00) << 8 ) | 
     1693           ((src & 0x00ff0000) >> 8 ) | 
     1694           ((src & 0xff000000) >> 24); 
     1695#endif 
     1696
    16651697 
    1666     std::swap(p[0], p[3]); 
    1667     std::swap(p[1], p[2]); 
     1698/*! Convert a UInt32 from big endian byte order to host byte order. 
    16681699 
     1700    \param[in] src Input value in big endian byte order. 
     1701    \return The input converted to host byte order. 
     1702 
     1703    \note An actual conversion only happens on little endian architectures. 
     1704 
     1705    \ingroup GrpBaseBaseMiscFn 
     1706 */ 
     1707inline 
     1708UInt32 osgBigEndianToHost(UInt32 src) 
     1709{ 
     1710#if BYTE_ORDER == LITTLE_ENDIAN 
     1711    return ((src & 0x000000ff) << 24) | 
     1712           ((src & 0x0000ff00) << 8 ) | 
     1713           ((src & 0x00ff0000) >> 8 ) | 
     1714           ((src & 0xff000000) >> 24); 
     1715#else 
    16691716    return src; 
     1717#endif 
    16701718} 
    16711719 
    1672 /*! Convert a Real64 from host byte order to network byte order. 
     1720/*! Convert a UInt32 from little endian byte order to host byte order. 
    16731721 
     1722    \param[in] src Input value in little endian byte order. 
     1723    \return The input converted to host byte order. 
     1724 
     1725    \note An actual conversion only happens on big endian architectures. 
     1726 
     1727    \ingroup GrpBaseBaseMiscFn 
     1728 */ 
     1729inline  
     1730UInt32 osgLittleEndianToHost(UInt32 src) 
     1731{ 
     1732#if BYTE_ORDER == LITTLE_ENDIAN 
     1733    return src; 
     1734#else 
     1735    return ((src & 0x000000ff) << 24) | 
     1736           ((src & 0x0000ff00) << 8 ) | 
     1737           ((src & 0x00ff0000) >> 8 ) | 
     1738           ((src & 0xff000000) >> 24); 
     1739#endif 
     1740} 
     1741 
     1742// define some macros for long long int literals (these are undef'ed below) 
     1743// XXX should these go into OSGBaseTypes.h ?? (cneumann) 
     1744#ifdef OSG_LONGLONG_HAS_LL 
     1745 
     1746#define OSG_UINT64_LITERAL(value)   \ 
     1747value##ULL 
     1748 
     1749#define OSG_INT64_LITERAL(value)    \ 
     1750value##LL 
     1751 
     1752#else 
     1753 
     1754#define OSG_UINT64_LITERAL(value)   \ 
     1755value##U 
     1756 
     1757#define OSG_INT64_LITERAL(value)    \ 
     1758value 
     1759 
     1760#endif 
     1761 
     1762/*! Convert a UInt64 from host byte order to big endian byte order. 
     1763 
    16741764    \param[in] src Input value in host byte order. 
    1675     \return The input converted to network byte order. 
     1765    \return The input converted to big endian byte order. 
    16761766 
    1677     \note Network byte order is big endian, so an actual conversion only 
    1678     happens on little endian architectures. 
     1767    \note An actual conversion only happens on little endian architectures. 
    16791768 
    16801769    \ingroup GrpBaseBaseMiscFn 
    16811770 */ 
    16821771inline 
    1683 Real64 osghtond(Real64 src) 
     1772UInt64 osgHostToBigEndian(UInt64 src) 
    16841773{ 
    1685     UInt8 *p = (UInt8 *) &src; 
     1774#if BYTE_ORDER == LITTLE_ENDIAN 
     1775    return ((src & OSG_UINT64_LITERAL(0x00000000000000ff)) << 56) | 
     1776           ((src & OSG_UINT64_LITERAL(0x000000000000ff00)) << 40) | 
     1777           ((src & OSG_UINT64_LITERAL(0x0000000000ff0000)) << 24) | 
     1778           ((src & OSG_UINT64_LITERAL(0x00000000ff000000)) << 8 ) | 
     1779           ((src & OSG_UINT64_LITERAL(0x000000ff00000000)) >> 8 ) | 
     1780           ((src & OSG_UINT64_LITERAL(0x0000ff0000000000)) >> 24) | 
     1781           ((src & OSG_UINT64_LITERAL(0x00ff000000000000)) >> 40) | 
     1782           ((src & OSG_UINT64_LITERAL(0xff00000000000000)) >> 56); 
     1783#else 
     1784    return src; 
     1785#endif 
     1786
    16861787 
    1687     std::swap(p[0], p[7]); 
    1688     std::swap(p[1], p[6]); 
    1689     std::swap(p[2], p[5]); 
    1690     std::swap(p[3], p[4]); 
     1788/*! Convert a UInt64 from host byte order to little endian byte order. 
    16911789 
     1790    \param[in] src Input value in host byte order. 
     1791    \return The input converted to little endian byte order. 
     1792 
     1793    \note An actual conversion only happens on big endian architectures. 
     1794 
     1795    \ingroup GrpBaseBaseMiscFn 
     1796 */ 
     1797inline 
     1798UInt64 osgHostToLittleEndian(UInt64 src) 
     1799{ 
     1800#if BYTE_ORDER == LITTLE_ENDIAN 
    16921801    return src; 
     1802#else 
     1803    return ((src & OSG_UINT64_LITERAL(0x00000000000000ff)) << 56) | 
     1804           ((src & OSG_UINT64_LITERAL(0x000000000000ff00)) << 40) | 
     1805           ((src & OSG_UINT64_LITERAL(0x0000000000ff0000)) << 24) | 
     1806           ((src & OSG_UINT64_LITERAL(0x00000000ff000000)) << 8 ) | 
     1807           ((src & OSG_UINT64_LITERAL(0x000000ff00000000)) >> 8 ) | 
     1808           ((src & OSG_UINT64_LITERAL(0x0000ff0000000000)) >> 24) | 
     1809           ((src & OSG_UINT64_LITERAL(0x00ff000000000000)) >> 40) | 
     1810           ((src & OSG_UINT64_LITERAL(0xff00000000000000)) >> 56); 
     1811#endif 
    16931812} 
    16941813 
    1695 /*! Convert a Real128 from host byte order to network byte order. 
     1814/*! Convert a UInt64 from big endian byte order to host byte order. 
    16961815 
    1697     \param[in] src Input value in host byte order. 
    1698     \return The input converted to network byte order. 
     1816    \param[in] src Input value in big endian byte order. 
     1817    \return The input converted to host byte order. 
    16991818 
    1700     \note Network byte order is big endian, so an actual conversion only 
    1701     happens on little endian architectures. 
     1819    \note An actual conversion only happens on little endian architectures. 
    17021820 
    17031821    \ingroup GrpBaseBaseMiscFn 
    17041822 */ 
    17051823inline 
    1706 Real128 osghtondd(Real128 src) 
     1824UInt64 osgBigEndianToHost(UInt64 src) 
    17071825{ 
    1708     UInt8 *p = (UInt8 *) &src; 
     1826#if BYTE_ORDER == LITTLE_ENDIAN 
     1827    return ((src & OSG_UINT64_LITERAL(0x00000000000000ff)) << 56) | 
     1828           ((src & OSG_UINT64_LITERAL(0x000000000000ff00)) << 40) | 
     1829           ((src & OSG_UINT64_LITERAL(0x0000000000ff0000)) << 24) | 
     1830           ((src & OSG_UINT64_LITERAL(0x00000000ff000000)) << 8 ) | 
     1831           ((src & OSG_UINT64_LITERAL(0x000000ff00000000)) >> 8 ) | 
     1832           ((src & OSG_UINT64_LITERAL(0x0000ff0000000000)) >> 24) | 
     1833           ((src & OSG_UINT64_LITERAL(0x00ff000000000000)) >> 40) | 
     1834           ((src & OSG_UINT64_LITERAL(0xff00000000000000)) >> 56); 
     1835#else 
     1836    return src; 
     1837#endif 
     1838
    17091839 
    1710     std::swap(p[0], p[15]); 
    1711     std::swap(p[1], p[14]); 
    1712     std::swap(p[2], p[13]); 
    1713     std::swap(p[3], p[12]); 
    1714     std::swap(p[4], p[11]); 
    1715     std::swap(p[5], p[10]); 
    1716     std::swap(p[6], p[9]); 
    1717     std::swap(p[7], p[8]); 
     1840/*! Convert a UInt64 from little endian byte order to host byte order. 
    17181841 
     1842    \param[in] src Input value in little endian byte order. 
     1843    \return The input converted to host byte order. 
     1844 
     1845    \note An actual conversion only happens on big endian architectures. 
     1846 
     1847    \ingroup GrpBaseBaseMiscFn 
     1848 */ 
     1849inline  
     1850UInt64 osgLittleEndianToHost(UInt64 src) 
     1851{ 
     1852#if BYTE_ORDER == LITTLE_ENDIAN 
    17191853    return src; 
     1854#else 
     1855    return ((src & OSG_UINT64_LITERAL(0x00000000000000ff)) << 56) | 
     1856           ((src & OSG_UINT64_LITERAL(0x000000000000ff00)) << 40) | 
     1857           ((src & OSG_UINT64_LITERAL(0x0000000000ff0000)) << 24) | 
     1858           ((src & OSG_UINT64_LITERAL(0x00000000ff000000)) << 8 ) | 
     1859           ((src & OSG_UINT64_LITERAL(0x000000ff00000000)) >> 8 ) | 
     1860           ((src & OSG_UINT64_LITERAL(0x0000ff0000000000)) >> 24) | 
     1861           ((src & OSG_UINT64_LITERAL(0x00ff000000000000)) >> 40) | 
     1862           ((src & OSG_UINT64_LITERAL(0xff00000000000000)) >> 56); 
     1863#endif 
    17201864} 
    17211865 
    1722 // network to host 
     1866// undef the long long int helper macros 
     1867#undef OSG_UINT64_LITERAL 
     1868#undef OSG_INT64_LITERAL 
    17231869 
    1724 /*! Convert a UInt16 from network byte order to host byte order. 
     1870/*! Convert a Real32 from host byte order to big endian byte order. 
    17251871 
    17261872    \param[in] src Input value in host byte order. 
    1727     \return The input converted to network byte order. 
     1873    \return The input converted to big endian byte order. 
    17281874 
    1729     \note Network byte order is big endian, so an actual conversion only 
    1730     happens on little endian architectures. 
     1875    \note An actual conversion only happens on little endian architectures. 
    17311876 
    17321877    \ingroup GrpBaseBaseMiscFn 
    17331878 */ 
    17341879inline 
    1735 UInt16 osgntohs(UInt16 src) 
     1880Real32 osgHostToBigEndian(Real32 src) 
    17361881{ 
    1737     return (src >> 8) | (src << 8); 
     1882#if BYTE_ORDER == LITTLE_ENDIAN 
     1883    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     1884     
     1885    std::swap(p[0], p[3]); 
     1886    std::swap(p[1], p[2]); 
     1887     
     1888    return src; 
     1889#else 
     1890    return src; 
     1891#endif 
    17381892} 
    17391893 
    1740 /*! Convert a UInt32 from network byte order to host byte order. 
     1894/*! Convert a Real32 from host byte order to little endian byte order. 
    17411895 
    17421896    \param[in] src Input value in host byte order. 
    1743     \return The input converted to network byte order. 
     1897    \return The input converted to little endian byte order. 
    17441898 
    1745     \note Network byte order is big endian, so an actual conversion only 
    1746     happens on little endian architectures. 
     1899    \note An actual conversion only happens on big endian architectures. 
    17471900 
    17481901    \ingroup GrpBaseBaseMiscFn 
    17491902 */ 
    17501903inline 
    1751 UInt32 osgntohl(UInt32 src) 
     1904Real32 osgHostToLittleEndian(Real32 src) 
    17521905{ 
    1753     return ((src&0x000000ff) << 24) | 
    1754            ((src&0x0000ff00) << 8 ) | 
    1755            ((src&0x00ff0000) >> 8 ) | 
    1756            ((src&0xff000000) >> 24); 
     1906#if BYTE_ORDER == LITTLE_ENDIAN 
     1907    return src; 
     1908#else 
     1909    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     1910     
     1911    std::swap(p[0], p[3]); 
     1912    std::swap(p[1], p[2]); 
     1913     
     1914    return src; 
     1915#endif 
    17571916} 
    17581917 
    1759 /*! Convert a UInt64 from network byte order to host byte order. 
     1918/*! Convert a Real32 from big endian byte order to host byte order. 
    17601919 
    1761     \param[in] src Input value in host byte order. 
    1762     \return The input converted to network byte order. 
     1920    \param[in] src Input value in big endian byte order. 
     1921    \return The input converted to host byte order. 
    17631922 
    1764     \note Network byte order is big endian, so an actual conversion only 
    1765     happens on little endian architectures. 
     1923    \note An actual conversion only happens on little endian architectures. 
    17661924 
    17671925    \ingroup GrpBaseBaseMiscFn 
    17681926 */ 
    17691927inline 
    1770 UInt64 osgntohll(UInt64 src) 
     1928Real32 osgBigEndianToHost(Real32 src) 
    17711929{ 
    1772 #ifdef OSG_LONGLONG_HAS_LL 
    1773     return ((src&0x00000000000000ffLL) << 56) | 
    1774            ((src&0x000000000000ff00LL) << 40) | 
    1775            ((src&0x0000000000ff0000LL) << 24) | 
    1776            ((src&0x00000000ff000000LL) << 8 ) | 
    1777            ((src&0x000000ff00000000LL) >> 8 ) | 
    1778            ((src&0x0000ff0000000000LL) >> 24) | 
    1779            ((src&0x00ff000000000000LL) >> 40) | 
    1780            ((src&0xff00000000000000LL) >> 56); 
     1930#if BYTE_ORDER == LITTLE_ENDIAN 
     1931    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     1932     
     1933    std::swap(p[0], p[3]); 
     1934    std::swap(p[1], p[2]); 
     1935     
     1936    return src; 
    17811937#else 
    1782     return ((src&0x00000000000000ff) << 56) | 
    1783            ((src&0x000000000000ff00) << 40) | 
    1784            ((src&0x0000000000ff0000) << 24) | 
    1785            ((src&0x00000000ff000000) << 8 ) | 
    1786            ((src&0x000000ff00000000) >> 8 ) | 
    1787            ((src&0x0000ff0000000000) >> 24) | 
    1788            ((src&0x00ff000000000000) >> 40) | 
    1789            ((src&0xff00000000000000) >> 56); 
     1938    return src; 
    17901939#endif 
    17911940} 
    17921941 
    1793 /*! Convert a Real32 from network byte order to host byte order. 
     1942/*! Convert a Real32 from little endian byte order to host byte order. 
    17941943 
    1795     \param[in] src Input value in host byte order. 
    1796     \return The input converted to network byte order. 
     1944    \param[in] src Input value in little endian byte order. 
     1945    \return The input converted to host byte order. 
    17971946 
    1798     \note Network byte order is big endian, so an actual conversion only 
    1799     happens on little endian architectures. 
     1947    \note An actual conversion only happens on big endian architectures. 
    18001948 
    18011949    \ingroup GrpBaseBaseMiscFn 
    18021950 */ 
    1803 inline 
    1804 Real32 osgntohf(Real32 src) 
     1951inline  
     1952Real32 osgLittleEndianToHost(Real32 src) 
    18051953{ 
    1806     UInt8 *p = (UInt8 *) &src; 
    1807  
     1954#if BYTE_ORDER == LITTLE_ENDIAN 
     1955    return src; 
     1956#else 
     1957    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     1958     
    18081959    std::swap(p[0], p[3]); 
    18091960    std::swap(p[1], p[2]); 
     1961     
     1962    return src; 
     1963#endif 
     1964} 
    18101965 
     1966/*! Convert a Real64 from host byte order to big endian byte order. 
     1967 
     1968    \param[in] src Input value in host byte order. 
     1969    \return The input converted to big endian byte order. 
     1970 
     1971    \note An actual conversion only happens on little endian architectures. 
     1972 
     1973    \ingroup GrpBaseBaseMiscFn 
     1974 */ 
     1975inline 
     1976Real64 osgHostToBigEndian(Real64 src) 
     1977{ 
     1978#if BYTE_ORDER == LITTLE_ENDIAN 
     1979    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     1980     
     1981    std::swap(p[0], p[7]); 
     1982    std::swap(p[1], p[6]); 
     1983    std::swap(p[2], p[5]); 
     1984    std::swap(p[3], p[4]); 
     1985     
    18111986    return src; 
     1987#else 
     1988    return src; 
     1989#endif 
    18121990} 
    18131991 
    1814 /*! Convert a Real64 from network byte order to host byte order. 
     1992/*! Convert a Real64 from host byte order to little endian byte order. 
    18151993 
    18161994    \param[in] src Input value in host byte order. 
    1817     \return The input converted to network byte order. 
     1995    \return The input converted to little endian byte order. 
    18181996 
    1819     \note Network byte order is big endian, so an actual conversion only 
    1820     happens on little endian architectures. 
     1997    \note An actual conversion only happens on big endian architectures. 
    18211998 
    18221999    \ingroup GrpBaseBaseMiscFn 
    18232000 */ 
    18242001inline 
    1825 Real64 osgntohd(Real64 src) 
     2002Real64 osgHostToLittleEndian(Real64 src) 
    18262003{ 
    1827     UInt8 *p = (UInt8 *) &src; 
     2004#if BYTE_ORDER == LITTLE_ENDIAN 
     2005    return src; 
     2006#else 
     2007    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2008     
     2009    std::swap(p[0], p[7]); 
     2010    std::swap(p[1], p[6]); 
     2011    std::swap(p[2], p[5]); 
     2012    std::swap(p[3], p[4]); 
     2013     
     2014    return src; 
     2015#endif 
     2016
    18282017 
     2018/*! Convert a Real64 from big endian byte order to host byte order. 
     2019 
     2020    \param[in] src Input value in big endian byte order. 
     2021    \return The input converted to host byte order. 
     2022 
     2023    \note An actual conversion only happens on little endian architectures. 
     2024 
     2025    \ingroup GrpBaseBaseMiscFn 
     2026 */ 
     2027inline 
     2028Real64 osgBigEndianToHost(Real64 src) 
     2029{ 
     2030#if BYTE_ORDER == LITTLE_ENDIAN 
     2031    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2032     
    18292033    std::swap(p[0], p[7]); 
    18302034    std::swap(p[1], p[6]); 
    18312035    std::swap(p[2], p[5]); 
    18322036    std::swap(p[3], p[4]); 
     2037     
     2038    return src; 
     2039#else 
     2040    return src; 
     2041#endif 
     2042} 
    18332043 
     2044/*! Convert a Real64 from little endian byte order to host byte order. 
     2045 
     2046    \param[in] src Input value in little endian byte order. 
     2047    \return The input converted to host byte order. 
     2048 
     2049    \note An actual conversion only happens on big endian architectures. 
     2050 
     2051    \ingroup GrpBaseBaseMiscFn 
     2052 */ 
     2053inline  
     2054Real64 osgLittleEndianToHost(Real64 src) 
     2055{ 
     2056#if BYTE_ORDER == LITTLE_ENDIAN 
    18342057    return src; 
     2058#else 
     2059    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2060     
     2061    std::swap(p[0], p[7]); 
     2062    std::swap(p[1], p[6]); 
     2063    std::swap(p[2], p[5]); 
     2064    std::swap(p[3], p[4]); 
     2065     
     2066    return src; 
     2067#endif 
    18352068} 
    18362069 
    1837 /*! Convert a Real128 from network byte order to host byte order. 
     2070/*! Convert a Real128 from host byte order to big endian byte order. 
    18382071 
    18392072    \param[in] src Input value in host byte order. 
    1840     \return The input converted to network byte order. 
     2073    \return The input converted to big endian byte order. 
    18412074 
    1842     \note Network byte order is big endian, so an actual conversion only 
    1843     happens on little endian architectures. 
     2075    \note An actual conversion only happens on little endian architectures. 
    18442076 
    18452077    \ingroup GrpBaseBaseMiscFn 
    18462078 */ 
    18472079inline 
    1848 Real128 osgntohdd(Real128 src) 
     2080Real128 osgHostToBigEndian(Real128 src) 
    18492081{ 
    1850     UInt8 *p = (UInt8 *) &src; 
     2082#if BYTE_ORDER == LITTLE_ENDIAN 
     2083    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2084     
     2085    std::swap(p[0], p[15]); 
     2086    std::swap(p[1], p[14]); 
     2087    std::swap(p[2], p[13]); 
     2088    std::swap(p[3], p[12]); 
     2089    std::swap(p[4], p[11]); 
     2090    std::swap(p[5], p[10]); 
     2091    std::swap(p[6], p[9]); 
     2092    std::swap(p[7], p[8]); 
     2093     
     2094    return src; 
     2095#else 
     2096    return src; 
     2097#endif 
     2098
    18512099 
     2100/*! Convert a Real128 from host byte order to little endian byte order. 
     2101 
     2102    \param[in] src Input value in host byte order. 
     2103    \return The input converted to little endian byte order. 
     2104 
     2105    \note An actual conversion only happens on big endian architectures. 
     2106 
     2107    \ingroup GrpBaseBaseMiscFn 
     2108 */ 
     2109inline 
     2110Real128 osgHostToLittleEndian(Real128 src) 
     2111{ 
     2112#if BYTE_ORDER == LITTLE_ENDIAN 
     2113    return src; 
     2114#else 
     2115    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2116     
    18522117    std::swap(p[0], p[15]); 
    18532118    std::swap(p[1], p[14]); 
    18542119    std::swap(p[2], p[13]); 
     
    18572122    std::swap(p[5], p[10]); 
    18582123    std::swap(p[6], p[9]); 
    18592124    std::swap(p[7], p[8]); 
     2125     
     2126    return src; 
     2127#endif 
     2128} 
    18602129 
     2130/*! Convert a Real128 from big endian byte order to host byte order. 
     2131 
     2132    \param[in] src Input value in big endian byte order. 
     2133    \return The input converted to host byte order. 
     2134 
     2135    \note An actual conversion only happens on little endian architectures. 
     2136 
     2137    \ingroup GrpBaseBaseMiscFn 
     2138 */ 
     2139inline 
     2140Real128 osgBigEndianToHost(Real128 src) 
     2141{ 
     2142#if BYTE_ORDER == LITTLE_ENDIAN 
     2143    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2144     
     2145    std::swap(p[0], p[15]); 
     2146    std::swap(p[1], p[14]); 
     2147    std::swap(p[2], p[13]); 
     2148    std::swap(p[3], p[12]); 
     2149    std::swap(p[4], p[11]); 
     2150    std::swap(p[5], p[10]); 
     2151    std::swap(p[6], p[9]); 
     2152    std::swap(p[7], p[8]); 
     2153     
    18612154    return src; 
     2155#else 
     2156    return src; 
     2157#endif 
    18622158} 
    18632159 
     2160/*! Convert a Real128 from little endian byte order to host byte order. 
     2161 
     2162    \param[in] src Input value in little endian byte order. 
     2163    \return The input converted to host byte order. 
     2164 
     2165    \note An actual conversion only happens on big endian architectures. 
     2166 
     2167    \ingroup GrpBaseBaseMiscFn 
     2168 */ 
     2169inline  
     2170Real128 osgLittleEndianToHost(Real128 src) 
     2171{ 
     2172#if BYTE_ORDER == LITTLE_ENDIAN 
     2173    return src; 
    18642174#else 
     2175    UInt8 *p = reinterpret_cast<UInt8*>(&src); 
     2176     
     2177    std::swap(p[0], p[15]); 
     2178    std::swap(p[1], p[14]); 
     2179    std::swap(p[2], p[13]); 
     2180    std::swap(p[3], p[12]); 
     2181    std::swap(p[4], p[11]); 
     2182    std::swap(p[5], p[10]); 
     2183    std::swap(p[6], p[9]); 
     2184    std::swap(p[7], p[8]); 
     2185     
     2186    return src; 
     2187#endif 
     2188} 
    18652189 
    1866 // host to network 
    1867 // perhaps we should use macros here ... 
    1868  
    18692190/*! Convert a UInt16 from host byte order to network byte order. 
    18702191 
    18712192    \param[in] src Input value in host byte order. 
     
    18792200inline 
    18802201UInt16 osghtons(UInt16 src) 
    18812202{ 
    1882     return src
     2203    return osgHostToBigEndian(src)
    18832204} 
    18842205 
    18852206/*! Convert a UInt32 from host byte order to network byte order. 
     
    18952216inline 
    18962217UInt32 osghtonl(UInt32 src) 
    18972218{ 
    1898     return src
     2219    return osgHostToBigEndian(src)
    18992220} 
    19002221 
    19012222/*! Convert a UInt64 from host byte order to network byte order. 
     
    19112232inline 
    19122233UInt64 osghtonll(UInt64 src) 
    19132234{ 
    1914     return src
     2235    return osgHostToBigEndian(src)
    19152236} 
    19162237 
    19172238/*! Convert a Real32 from host byte order to network byte order. 
     
    19272248inline 
    19282249Real32 osghtonf(Real32 src) 
    19292250{ 
    1930     return src
     2251    return osgHostToBigEndian(src)
    19312252} 
    19322253 
    19332254/*! Convert a Real64 from host byte order to network byte order. 
     
    19432264inline 
    19442265Real64 osghtond(Real64 src) 
    19452266{ 
    1946     return src
     2267    return osgHostToBigEndian(src)
    19472268} 
    19482269 
    19492270/*! Convert a Real128 from host byte order to network byte order. 
     
    19592280inline 
    19602281Real128 osghtondd(Real128 src) 
    19612282{ 
    1962     return src
     2283    return osgHostToBigEndian(src)
    19632284} 
    19642285 
    1965 // network to host 
    1966  
    19672286/*! Convert a UInt16 from network byte order to host byte order. 
    19682287 
    19692288    \param[in] src Input value in host byte order. 
     
    19772296inline 
    19782297UInt16 osgntohs(UInt16 src) 
    19792298{ 
    1980     return src
     2299    return osgBigEndianToHost(src)
    19812300} 
    19822301 
    19832302/*! Convert a UInt32 from network byte order to host byte order. 
     
    19932312inline 
    19942313UInt32 osgntohl(UInt32 src) 
    19952314{ 
    1996     return src
     2315    return osgBigEndianToHost(src)
    19972316} 
    19982317 
    19992318/*! Convert a UInt64 from network byte order to host byte order. 
     
    20092328inline 
    20102329UInt64 osgntohll(UInt64 src) 
    20112330{ 
    2012     return src
     2331    return osgBigEndianToHost(src)
    20132332} 
    20142333 
    20152334/*! Convert a Real32 from network byte order to host byte order. 
     
    20252344inline 
    20262345Real32 osgntohf(Real32 src) 
    20272346{ 
    2028     return src
     2347    return osgBigEndianToHost(src)
    20292348} 
    20302349 
    20312350/*! Convert a Real64 from network byte order to host byte order. 
     
    20412360inline 
    20422361Real64 osgntohd(Real64 src) 
    20432362{ 
    2044     return src
     2363    return osgBigEndianToHost(src)
    20452364} 
    20462365 
    20472366/*! Convert a Real128 from network byte order to host byte order. 
     
    20572376inline 
    20582377Real128 osgntohdd(Real128 src) 
    20592378{ 
    2060     return src
     2379    return osgBigEndianToHost(src)
    20612380} 
    20622381 
    2063 #endif 
    2064  
    20652382/*! \}                                                                 */ 
    20662383/*---------------------------------------------------------------------*/ 
    20672384/*! \name C strings                                                    */