/ggb_v1.0_src/ggb/util.h

http://ghostcb.googlecode.com/ · C Header · 81 lines · 47 code · 12 blank · 22 comment · 0 complexity · 627f34c475206ab5eab27a5890a731cc MD5 · raw file

  1. /*
  2. Copyright 2010 Trevor Hogan
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #ifndef UTIL_H
  14. #define UTIL_H
  15. // byte arrays
  16. BYTEARRAY UTIL_CreateByteArray( unsigned char *a, int size );
  17. BYTEARRAY UTIL_CreateByteArray( unsigned char c );
  18. BYTEARRAY UTIL_CreateByteArray( uint16_t i, bool reverse );
  19. BYTEARRAY UTIL_CreateByteArray( uint32_t i, bool reverse );
  20. uint16_t UTIL_ByteArrayToUInt16( BYTEARRAY b, bool reverse, unsigned int start = 0 );
  21. uint32_t UTIL_ByteArrayToUInt32( BYTEARRAY b, bool reverse, unsigned int start = 0 );
  22. string UTIL_ByteArrayToDecString( BYTEARRAY b );
  23. string UTIL_ByteArrayToHexString( BYTEARRAY b );
  24. void UTIL_AppendByteArray( BYTEARRAY &b, BYTEARRAY append );
  25. void UTIL_AppendByteArrayFast( BYTEARRAY &b, BYTEARRAY &append );
  26. void UTIL_AppendByteArray( BYTEARRAY &b, unsigned char *a, int size );
  27. void UTIL_AppendByteArray( BYTEARRAY &b, string append, bool terminator = true );
  28. void UTIL_AppendByteArrayFast( BYTEARRAY &b, string &append, bool terminator = true );
  29. void UTIL_AppendByteArray( BYTEARRAY &b, uint16_t i, bool reverse );
  30. void UTIL_AppendByteArray( BYTEARRAY &b, uint32_t i, bool reverse );
  31. BYTEARRAY UTIL_ExtractCString( BYTEARRAY &b, unsigned int start );
  32. unsigned char UTIL_ExtractHex( BYTEARRAY &b, unsigned int start, bool reverse );
  33. BYTEARRAY UTIL_ExtractNumbers( string s, unsigned int count );
  34. BYTEARRAY UTIL_ExtractHexNumbers( string s );
  35. // conversions
  36. string UTIL_ToString( unsigned long i );
  37. string UTIL_ToString( unsigned short i );
  38. string UTIL_ToString( unsigned int i );
  39. string UTIL_ToString( long i );
  40. string UTIL_ToString( short i );
  41. string UTIL_ToString( int i );
  42. string UTIL_ToString( float f, int digits );
  43. string UTIL_ToString( double d, int digits );
  44. string UTIL_ToHexString( uint32_t i );
  45. uint16_t UTIL_ToUInt16( string &s );
  46. uint32_t UTIL_ToUInt32( string &s );
  47. int16_t UTIL_ToInt16( string &s );
  48. int32_t UTIL_ToInt32( string &s );
  49. double UTIL_ToDouble( string &s );
  50. string UTIL_MSToString( uint32_t ms );
  51. // files
  52. bool UTIL_FileExists( string file );
  53. string UTIL_FileRead( string file, uint32_t start, uint32_t length );
  54. string UTIL_FileRead( string file );
  55. bool UTIL_FileWrite( string file, unsigned char *data, uint32_t length );
  56. string UTIL_FileSafeName( string fileName );
  57. string UTIL_AddPathSeperator( string path );
  58. // stat strings
  59. BYTEARRAY UTIL_EncodeStatString( BYTEARRAY &data );
  60. BYTEARRAY UTIL_DecodeStatString( BYTEARRAY &data );
  61. // bnet packets functions
  62. bool UTIL_AssignLength( BYTEARRAY &content);
  63. bool UTIL_ValidateLength( BYTEARRAY &content );
  64. #endif