Library code style update + some minor backports from Pro edition
This commit is contained in:
parent
593b291e85
commit
2607113727
68 changed files with 4538 additions and 4665 deletions
108
lib/bitfields.h
108
lib/bitfields.h
|
@ -1,39 +1,38 @@
|
|||
#pragma once
|
||||
#include "defines.h"
|
||||
#include <string>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace Util{
|
||||
bool stringToBool(std::string & str);
|
||||
bool stringToBool(std::string &str);
|
||||
}
|
||||
|
||||
namespace Bit{
|
||||
//bitfield getters
|
||||
unsigned long long getMSB(char * pointer, unsigned int offsetBits, unsigned int dataBits);
|
||||
unsigned long long getByName(char * pointer);
|
||||
//bitfield setters
|
||||
void setMSB(char * pointer, unsigned int offsetBits, unsigned int dataBits, unsigned long long value);
|
||||
void setByName(char * pointer);
|
||||
// bitfield getters
|
||||
unsigned long long getMSB(char *pointer, unsigned int offsetBits, unsigned int dataBits);
|
||||
unsigned long long getByName(char *pointer);
|
||||
// bitfield setters
|
||||
void setMSB(char *pointer, unsigned int offsetBits, unsigned int dataBits,
|
||||
unsigned long long value);
|
||||
void setByName(char *pointer);
|
||||
|
||||
//Host to binary/binary to host functions - similar to kernel ntoh/hton functions.
|
||||
// Host to binary/binary to host functions - similar to kernel ntoh/hton functions.
|
||||
|
||||
/// Retrieves a short in network order from the pointer p.
|
||||
inline unsigned short btohs(const char * p) {
|
||||
return ((unsigned short)p[0] << 8) | p[1];
|
||||
}
|
||||
inline uint16_t btohs(const char *p){return ((uint16_t)p[0] << 8) | p[1];}
|
||||
|
||||
/// Stores a short value of val in network order to the pointer p.
|
||||
inline void htobs(char * p, unsigned short val) {
|
||||
inline void htobs(char *p, uint16_t val){
|
||||
p[0] = (val >> 8) & 0xFF;
|
||||
p[1] = val & 0xFF;
|
||||
}
|
||||
|
||||
/// Retrieves a long in network order from the pointer p.
|
||||
inline unsigned long btohl(const char * p) {
|
||||
return ((unsigned long)p[0] << 24) | ((unsigned long)p[1] << 16) | ((unsigned long)p[2] << 8) | p[3];
|
||||
inline uint32_t btohl(const char *p){
|
||||
return ((uint32_t)p[0] << 24) | ((uint32_t)p[1] << 16) | ((uint32_t)p[2] << 8) | p[3];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in network order to the pointer p.
|
||||
inline void htobl(char * p, unsigned long val) {
|
||||
inline void htobl(char *p, uint32_t val){
|
||||
p[0] = (val >> 24) & 0xFF;
|
||||
p[1] = (val >> 16) & 0xFF;
|
||||
p[2] = (val >> 8) & 0xFF;
|
||||
|
@ -41,24 +40,25 @@ namespace Bit{
|
|||
}
|
||||
|
||||
/// Retrieves a long in network order from the pointer p.
|
||||
inline unsigned long btoh24(const char * p) {
|
||||
inline unsigned long btoh24(const char *p){
|
||||
return ((unsigned long)p[0] << 16) | ((unsigned long)p[1] << 8) | p[2];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in network order to the pointer p.
|
||||
inline void htob24(char * p, unsigned long val) {
|
||||
inline void htob24(char *p, unsigned long val){
|
||||
p[0] = (val >> 16) & 0xFF;
|
||||
p[1] = (val >> 8) & 0xFF;
|
||||
p[2] = val & 0xFF;
|
||||
}
|
||||
|
||||
/// Retrieves a 40-bit uint in network order from the pointer p.
|
||||
inline uint64_t btoh40(const char * p) {
|
||||
return ((uint64_t)p[0] << 32) | ((uint64_t)p[1] << 24) | ((uint64_t)p[2] << 16) | ((uint64_t)p[3] << 8) | p[4];
|
||||
inline uint64_t btoh40(const char *p){
|
||||
return ((uint64_t)p[0] << 32) | ((uint64_t)p[1] << 24) | ((uint64_t)p[2] << 16) |
|
||||
((uint64_t)p[3] << 8) | p[4];
|
||||
}
|
||||
|
||||
/// Stores a 40-bit uint value of val in network order to the pointer p.
|
||||
inline void htob40(char * p, uint64_t val) {
|
||||
inline void htob40(char *p, uint64_t val){
|
||||
p[0] = (val >> 32) & 0xFF;
|
||||
p[1] = (val >> 24) & 0xFF;
|
||||
p[2] = (val >> 16) & 0xFF;
|
||||
|
@ -67,12 +67,13 @@ namespace Bit{
|
|||
}
|
||||
|
||||
/// Retrieves a 48-bit uint in network order from the pointer p.
|
||||
inline uint64_t btoh48(const char * p) {
|
||||
return ((uint64_t)p[0] << 40) | ((uint64_t)p[1] << 32) | ((uint64_t)p[2] << 24) | ((uint64_t)p[3] << 16) | ((uint64_t)p[4] << 8) | p[5];
|
||||
inline uint64_t btoh48(const char *p){
|
||||
return ((uint64_t)p[0] << 40) | ((uint64_t)p[1] << 32) | ((uint64_t)p[2] << 24) |
|
||||
((uint64_t)p[3] << 16) | ((uint64_t)p[4] << 8) | p[5];
|
||||
}
|
||||
|
||||
/// Stores a 48-bit uint value of val in network order to the pointer p.
|
||||
inline void htob48(char * p, uint64_t val) {
|
||||
inline void htob48(char *p, uint64_t val){
|
||||
p[0] = (val >> 40) & 0xFF;
|
||||
p[1] = (val >> 32) & 0xFF;
|
||||
p[2] = (val >> 24) & 0xFF;
|
||||
|
@ -82,12 +83,13 @@ namespace Bit{
|
|||
}
|
||||
|
||||
/// Retrieves a 56-bit uint in network order from the pointer p.
|
||||
inline uint64_t btoh56(const char * p) {
|
||||
return ((uint64_t)p[0] << 48) | ((uint64_t)p[1] << 40) | ((uint64_t)p[2] << 32) | ((uint64_t)p[3] << 24) | ((uint64_t)p[4] << 16) | ((uint64_t)p[5] << 8) | p[6];
|
||||
inline uint64_t btoh56(const char *p){
|
||||
return ((uint64_t)p[0] << 48) | ((uint64_t)p[1] << 40) | ((uint64_t)p[2] << 32) |
|
||||
((uint64_t)p[3] << 24) | ((uint64_t)p[4] << 16) | ((uint64_t)p[5] << 8) | p[6];
|
||||
}
|
||||
|
||||
/// Stores a 56-bit uint value of val in network order to the pointer p.
|
||||
inline void htob56(char * p, uint64_t val) {
|
||||
inline void htob56(char *p, uint64_t val){
|
||||
p[0] = (val >> 48) & 0xFF;
|
||||
p[1] = (val >> 40) & 0xFF;
|
||||
p[2] = (val >> 32) & 0xFF;
|
||||
|
@ -98,12 +100,14 @@ namespace Bit{
|
|||
}
|
||||
|
||||
/// Retrieves a long long in network order from the pointer p.
|
||||
inline unsigned long long btohll(const char * p) {
|
||||
return ((unsigned long long)p[0] << 56) | ((unsigned long long)p[1] << 48) | ((unsigned long long)p[2] << 40) | ((unsigned long long)p[3] << 32) | ((unsigned long)p[4] << 24) | ((unsigned long)p[5] << 16) | ((unsigned long)p[6] << 8) | p[7];
|
||||
inline uint64_t btohll(const char *p){
|
||||
return ((uint64_t)p[0] << 56) | ((uint64_t)p[1] << 48) | ((uint64_t)p[2] << 40) |
|
||||
((uint64_t)p[3] << 32) | ((uint64_t)p[4] << 24) | ((uint64_t)p[5] << 16) |
|
||||
((uint64_t)p[6] << 8) | p[7];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in network order to the pointer p.
|
||||
inline void htobll(char * p, unsigned long long val) {
|
||||
inline void htobll(char *p, unsigned long long val){
|
||||
p[0] = (val >> 56) & 0xFF;
|
||||
p[1] = (val >> 48) & 0xFF;
|
||||
p[2] = (val >> 40) & 0xFF;
|
||||
|
@ -114,42 +118,37 @@ namespace Bit{
|
|||
p[7] = val & 0xFF;
|
||||
}
|
||||
|
||||
inline float btohf(const char * p){
|
||||
inline float btohf(const char *p){
|
||||
uint32_t tmp = btohl(p);
|
||||
return *reinterpret_cast<float*>(&tmp);
|
||||
return *reinterpret_cast<float *>(&tmp);
|
||||
}
|
||||
|
||||
inline void htobf(char * p, float val){
|
||||
htobl(p, *reinterpret_cast<unsigned long*>(&val));
|
||||
}
|
||||
inline void htobf(char *p, float val){htobl(p, *reinterpret_cast<uint32_t *>(&val));}
|
||||
|
||||
inline double btohd(const char * p){
|
||||
inline double btohd(const char *p){
|
||||
uint64_t tmp = btohll(p);
|
||||
return *reinterpret_cast<double*>(&tmp);
|
||||
return *reinterpret_cast<double *>(&tmp);
|
||||
}
|
||||
|
||||
inline void htobd(char * p, double val){
|
||||
htobll(p, *reinterpret_cast<unsigned long*>(&val));
|
||||
}
|
||||
inline void htobd(char *p, double val){htobll(p, *reinterpret_cast<uint32_t *>(&val));}
|
||||
|
||||
/// Retrieves a short in little endian from the pointer p.
|
||||
inline unsigned short btohs_le(const char * p) {
|
||||
return ((unsigned short)p[1] << 8) | p[0];
|
||||
}
|
||||
inline uint16_t btohs_le(const char *p){return ((uint16_t)p[1] << 8) | p[0];}
|
||||
|
||||
/// Stores a short value of val in little endian to the pointer p.
|
||||
inline void htobs_le(char * p, unsigned short val) {
|
||||
inline void htobs_le(char *p, unsigned short val){
|
||||
p[1] = (val >> 8) & 0xFF;
|
||||
p[0] = val & 0xFF;
|
||||
}
|
||||
|
||||
/// Retrieves a long in network order from the pointer p.
|
||||
inline unsigned long btohl_le(const char * p) {
|
||||
return ((unsigned long)p[3] << 24) | ((unsigned long)p[2] << 16) | ((unsigned long)p[1] << 8) | p[0];
|
||||
inline unsigned long btohl_le(const char *p){
|
||||
return ((unsigned long)p[3] << 24) | ((unsigned long)p[2] << 16) | ((unsigned long)p[1] << 8) |
|
||||
p[0];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in little endian to the pointer p.
|
||||
inline void htobl_le(char * p, unsigned long val) {
|
||||
inline void htobl_le(char *p, unsigned long val){
|
||||
p[3] = (val >> 24) & 0xFF;
|
||||
p[2] = (val >> 16) & 0xFF;
|
||||
p[1] = (val >> 8) & 0xFF;
|
||||
|
@ -157,24 +156,27 @@ namespace Bit{
|
|||
}
|
||||
|
||||
/// Retrieves a long in little endian from the pointer p.
|
||||
inline unsigned long btoh24_le(const char * p) {
|
||||
inline unsigned long btoh24_le(const char *p){
|
||||
return ((unsigned long)p[2] << 16) | ((unsigned long)p[1] << 8) | p[0];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in network order to the pointer p.
|
||||
inline void htob24_le(char * p, unsigned long val) {
|
||||
inline void htob24_le(char *p, unsigned long val){
|
||||
p[2] = (val >> 16) & 0xFF;
|
||||
p[1] = (val >> 8) & 0xFF;
|
||||
p[0] = val & 0xFF;
|
||||
}
|
||||
|
||||
/// Retrieves a long long in little endian from the pointer p.
|
||||
inline unsigned long long btohll_le(const char * p) {
|
||||
return ((unsigned long long)p[7] << 56) | ((unsigned long long)p[6] << 48) | ((unsigned long long)p[5] << 40) | ((unsigned long long)p[4] << 32) | ((unsigned long)p[3] << 24) | ((unsigned long)p[2] << 16) | ((unsigned long)p[1] << 8) | p[0];
|
||||
inline unsigned long long btohll_le(const char *p){
|
||||
return ((unsigned long long)p[7] << 56) | ((unsigned long long)p[6] << 48) |
|
||||
((unsigned long long)p[5] << 40) | ((unsigned long long)p[4] << 32) |
|
||||
((unsigned long)p[3] << 24) | ((unsigned long)p[2] << 16) | ((unsigned long)p[1] << 8) |
|
||||
p[0];
|
||||
}
|
||||
|
||||
/// Stores a long value of val in little endian to the pointer p.
|
||||
inline void htobll_le(char * p, unsigned long long val) {
|
||||
inline void htobll_le(char *p, unsigned long long val){
|
||||
p[7] = (val >> 56) & 0xFF;
|
||||
p[6] = (val >> 48) & 0xFF;
|
||||
p[5] = (val >> 40) & 0xFF;
|
||||
|
@ -185,5 +187,5 @@ namespace Bit{
|
|||
p[0] = val & 0xFF;
|
||||
}
|
||||
|
||||
}
|
||||
}// namespace Bit
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue