PageRenderTime 55ms CodeModel.GetById 41ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 0ms

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