# HG changeset patch # User Teemu Piippo # Date 1342401349 -10800 # Node ID b4e09ae24bf178010d540b4c88011f2b604dfae3 # Parent fb46d3d40064063b4cf5ba00973ed67765f35a7b Moved CharByte inside DataBuffer since that's where it belongs anyway. diff -r fb46d3d40064 -r b4e09ae24bf1 commands.def --- a/commands.def Mon Jul 16 04:07:15 2012 +0300 +++ b/commands.def Mon Jul 16 04:15:49 2012 +0300 @@ -1,5 +1,5 @@ -/* This file defines the commands botc will treat as valid. Do not edit unless - * you know what you are doing! +/* This file defines the commands botc will treat as valid. + * Do not edit unless you know what you are doing! * * Syntax: number:name:returntype:numargs:maxargs[:argumentlist] */ diff -r fb46d3d40064 -r b4e09ae24bf1 common.h --- a/common.h Mon Jul 16 04:07:15 2012 +0300 +++ b/common.h Mon Jul 16 04:15:49 2012 +0300 @@ -100,20 +100,4 @@ return r; } -template unsigned char CharByte (T a, unsigned int b) { - if (b >= sizeof (T)) - error ("CharByte: tried to get byte %u out of a %u-byte %s\n", - b, sizeof (T), typeid(T).name()); - - unsigned long p1 = pow (256, b); - unsigned long p2 = pow (256, b+1); - unsigned long r = (a % p2) / p1; - - if (r > 256) - error ("result %lu too big!", r); - - unsigned char ur = static_cast (r); - return ur; -} - #endif // __COMMON_H__ \ No newline at end of file diff -r fb46d3d40064 -r b4e09ae24bf1 objwriter.h --- a/objwriter.h Mon Jul 16 04:07:15 2012 +0300 +++ b/objwriter.h Mon Jul 16 04:15:49 2012 +0300 @@ -109,12 +109,29 @@ writepos++; } } - + template T Read() { T result = buffer[readpos]; readpos += sizeof (T); return result; } + +private: + template unsigned char CharByte (T a, unsigned int b) { + if (b >= sizeof (T)) + error ("CharByte: tried to get byte %u out of a %u-byte %s\n", + b, sizeof (T), typeid(T).name()); + + unsigned long p1 = pow (256, b); + unsigned long p2 = pow (256, b+1); + unsigned long r = (a % p2) / p1; + + if (r > 256) + error ("result %lu too big!", r); + + unsigned char ur = static_cast (r); + return ur; + } }; class ObjWriter {