LoadSave Class Reference#include <LoadSave.h>
Inheritance diagram for LoadSave:
[legend]List of all members.
Detailed Description
Intended as an interface to allow easy and uniform file operations.
Generally, for usage, all you need to know is to call SaveFile("/path/to/file.ext") or SaveBuffer(membuffer) in order to have the class serialize itself, and the LoadFile() / LoadBuffer() in order to reload the data.
So, when SaveFile() is called, it checks that it can open the specified file, and then calls SaveFileStream() with the open file. This will then check getBinSize(), create a buffer of that size, and call SaveBuffer() to do the actual work of serialization into that buffer. If SaveBuffer is successful (make sure your getBinSize() doesn't underestimate!) SaveFileStream() copies the buffer out to the file, and then finally, SaveFile() will close the file.
This has the nice side effect that if you want to send the data over the network instead of a file, you can call SaveBuffer() directly and reuse the code. However, if you have a lot of data to save, you can override the SaveFileStream() function as well, and save into the file directly. So far I've only bothered to do that with only a few classes.
The recommended style for using LoadSave in classes with inheritance is to have each subclass first call the superclass's implementation, and then save their own local data. This compartmentalizes the data access and makes it easy to maintain - the code that serializes is right in with the code that defines the structure. If you change one, it's easy to see where to change the other. And protection between levels of inheritance is retained. (This is why I say it's highly flexible/maintainable, but poor readability since the serialization is all broken up.)
I also recommend putting a little string header at the beginning of each class's info. This will allow polymorphism when loading files (you can look at the string and create the appropriate type) but also is handy for checking field alignment... it's a lot easier to tell how much you're offset within a string than to do the same with a stream of binary values. Further, you can use the string as version information if you want to be backward compatible in future versions of your code.
LoadSave provides a series of encode and decode functions for all the primitive types. This will handle copying the value into the buffer or file, and can provide platform independence through byte swapping if needed (there's a compiler flag you can set for platforms that have the opposite byte order). Most of these are pretty straightfoward - an int is just 4 bytes and so on.
However, there's one caveat that I want to make sure to point out if you have to write parsing code in say, Java. Strings are encoded by first storing an int to hold the string's length, then the string itself, and then a null character. This adds 5 bytes to the length of any string, but makes loading the files much easier/faster - you can call string library functions directly on the buffer if it's already in memory since the string is null terminated, or can allocate memory to hold the string during loading from a file if needed because you'll know the size of the string before you get to it.
Of course, the string stuff is transparent if you just use LoadSave's encode/decode functions to parse it. But if that's not available (for instance if your receiver is in Java, there's a readLoadSaveString() in VisionListener.java if that will help: http://cvs.tekkotsu.org/cgi-bin/viewcvs.cgi/Tekkotsu/tools/mon/org/tekkotsu/mon/VisionListener.java?rev=1.6&content-type=text/vnd.viewcvs-markup public boolean _isConnected;
public String readLoadSaveString(InputStream in) throws java.io.IOException {
int creatorLen=readInt(in);
if(!_isConnected) return "";
String creator=new String(readBytes(in,creatorLen));
if(!_isConnected) return "";
if(readChar(in)!='\0')
System.err.println("Misread LoadSave string? "+creator);
return creator;
}
public int readInt(InputStream in) throws IOException {
int read=0;
int last=0;
byte[] buf=new byte[4];
while (read<4 && last>=0) { last=in.read(buf,read,4-read); read+=last; }
if(last<0)
_isConnected=false;
return (b2i(buf[3])<<24) | (b2i(buf[2])<<16) |
(b2i(buf[1])<< 8) | b2i(buf[0]);
}
public byte[] readBytes(InputStream in, int bytes) throws IOException {
byte[] ret=new byte[bytes];
readBytes(ret, in, bytes);
return ret;
}
public char readChar(InputStream in) throws IOException {
return (char)in.read();
}
Definition at line 133 of file LoadSave.h.
|
Public Member Functions |
|
| LoadSave () |
| constructor
|
virtual | ~LoadSave () |
| destructor
|
|
These are useful for sending the data across a network as well as to a file.
These are the only ones that MUST be overridden, as the file ops can be based on calling these, tho feel free to override the file ops as well if speed or temp. memory is tight.
|
virtual unsigned int | getBinSize () const =0 |
| calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.
|
virtual unsigned int | LoadBuffer (const char buf[], unsigned int len)=0 |
| Load from a saved buffer.
|
virtual unsigned int | SaveBuffer (char buf[], unsigned int len) const =0 |
| Save to a given buffer.
|
|
These are called to load and save to files
|
virtual unsigned int | LoadFile (const char *filename) |
| initiate opening of the specified file and loading/saving of all appropriate information.
|
virtual unsigned int | SaveFile (const char *filename) const |
| initiate opening of the specified file and loading/saving of all appropriate information.
|
virtual unsigned int | LoadFileStream (FILE *f) |
| Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.
|
virtual unsigned int | SaveFileStream (FILE *f) const |
| Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.
|
|
These are for putting creator codes at the beginning of your data to check for sanity, just optional
|
virtual unsigned int | creatorSize (const char creator[]) const |
| Returns size of the creator code.
|
virtual unsigned int | checkCreator (const char *creator, const char buf[], unsigned int len, bool isLoading=true) const |
| Compares the creator code in the buffer to the one given.
|
virtual unsigned int | checkCreator (const char *creator, FILE *f, bool isLoading=true) const |
| Compares the creator code in the file to the one given, will attempt to reset the file position if fails (so you can check for one of several types).
|
virtual unsigned int | saveCreator (const char *creator, char buf[], unsigned int len) const |
| Saves a creator code to a buffer.
|
virtual unsigned int | saveCreator (const char *creator, FILE *f) const |
| Saves a creator code directly to a file.
|
Static Public Member Functions |
static bool | ChkAdvance (int res, const char **buf, unsigned int *len, const char *msg) |
| Handy for checking results from functions which manipulate the buffer.
|
static bool | ChkAdvance (int res, const char **buf, unsigned int *len, const char *msg, int arg1) |
| Handy for checking results from functions which manipulate the buffer.
|
|
encode/decode cross-platform compatable (byte order consistancy)
|
static unsigned int | encode (const LoadSave &x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (LoadSave &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const LoadSave &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (LoadSave &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const double x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (double &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const double x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (double &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const float x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (float &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const float x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (float &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const long x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (long &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const long x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (long &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned long x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned long &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned long x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned long &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const int x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (int &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const int x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (int &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned int x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned int &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned int x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned int &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const short x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (short &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const short x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (short &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned short x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned short &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned short x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned short &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const std::string &x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (std::string &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const std::string &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (std::string &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const char *x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (char *&x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const char *x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (char *&x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const char x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (char &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const char x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (char &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned char x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned char &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const unsigned char x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (unsigned char &x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const bool x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (bool &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
static unsigned int | encode (const bool x, FILE *f) |
| encode or decode with byte order consistancy
|
static unsigned int | decode (bool &x, FILE *f) |
| encode or decode with byte order consistancy
|
Static Public Attributes |
static const unsigned int | stringpad = sizeof(unsigned int)+1 |
| This is the amount of extra space needed to store a string (int for len of string plus 1 for null term.
|
Static Protected Member Functions |
template<class T> |
static void | byteswap (T &dstc, const T &srcc) |
| templated function to swap byte ordering, should allow compiler to unroll the loop; warning don't use this if src==dst!!!
|
Constructor & Destructor Documentation
LoadSave::LoadSave |
( |
|
) |
[inline] |
|
LoadSave::~LoadSave |
( |
|
) |
[virtual] |
|
Member Function Documentation
template<class T> |
static void LoadSave::byteswap |
( |
T & |
dstc, |
|
|
const T & |
srcc |
|
) |
[inline, static, protected] |
|
|
templated function to swap byte ordering, should allow compiler to unroll the loop; warning don't use this if src==dst!!!
Definition at line 360 of file LoadSave.h. |
unsigned int LoadSave::checkCreator |
( |
const char * |
creator, |
|
|
FILE * |
f, |
|
|
bool |
isLoading = true |
|
) |
const [virtual] |
|
|
Compares the creator code in the file to the one given, will attempt to reset the file position if fails (so you can check for one of several types).
- Parameters:
-
| creator | what the creator should be |
| f | the file pointer to check |
| isLoading | set this to true if you want to output a warning if it doesn't match |
- Returns:
- the number of bytes consumed by the creator code, or 0 if it didn't match
Definition at line 20 of file LoadSave.cc. |
unsigned int LoadSave::checkCreator |
( |
const char * |
creator, |
|
|
const char |
buf[], |
|
|
unsigned int |
len, |
|
|
bool |
isLoading = true |
|
) |
const [virtual] |
|
bool LoadSave::ChkAdvance |
( |
int |
res, |
|
|
const char ** |
buf, |
|
|
unsigned int * |
len, |
|
|
const char * |
msg, |
|
|
int |
arg1 |
|
) |
[static] |
|
|
Handy for checking results from functions which manipulate the buffer.
This really should be rewritten to use variable number of arguments which can be passed directly on to printf... - Parameters:
-
| res | number of bytes used |
| buf | pointer to address of current place in buffer, will be incremented by res bytes |
| len | number of bytes remain between current place and end of buffer, will be decremented by res bytes |
| msg | Error to display if res is less than or equal to zero |
| arg1 | An additional argument to be displayed (using d in the msg); intended for things such as line number of error in file being read |
- Returns:
- true if everything worked, false otherwise
Definition at line 146 of file LoadSave.cc. |
bool LoadSave::ChkAdvance |
( |
int |
res, |
|
|
const char ** |
buf, |
|
|
unsigned int * |
len, |
|
|
const char * |
msg |
|
) |
[static] |
|
virtual unsigned int LoadSave::creatorSize |
( |
const char |
creator[] |
) |
const [inline, virtual] |
|
static unsigned int LoadSave::decode |
( |
bool & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 356 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
bool & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 354 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned char & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 351 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned char & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 349 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
char & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 347 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
char & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 345 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
char *& |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 342 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
char *& |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 340 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
std::string & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 337 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
std::string & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 335 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned short & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 330 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned short & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 328 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
short & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 326 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
short & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 324 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned int & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 321 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned int & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 319 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
int & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 317 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
int & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 315 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned long & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 313 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
unsigned long & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 311 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
long & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 309 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
long & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 307 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
float & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 304 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
float & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 302 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
double & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 299 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
double & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 297 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
LoadSave & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 254 of file LoadSave.h. |
static unsigned int LoadSave::decode |
( |
LoadSave & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 252 of file LoadSave.h.
Referenced by checkCreator(), decode(), SegmentedColorGenerator::decodeColors(), VisionObjectEvent::LoadBinaryBuffer(), TextMsgEvent::LoadBinaryBuffer(), LocomotionEvent::LoadBinaryBuffer(), EventBase::LoadBinaryBuffer(), WalkMC::LoadBuffer(), SegmentedColorGenerator::LoadBuffer(), RLEGenerator::LoadBuffer(), RegionGenerator::LoadBuffer(), RawCameraGenerator::LoadBuffer(), JPEGGenerator::LoadBuffer(), InterleavedYUVGenerator::LoadBuffer(), FilterBankGenerator::LoadBuffer(), and BufferedImageGenerator::LoadBuffer(). |
static unsigned int LoadSave::encode |
( |
const bool |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 355 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const bool |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 353 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned char |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 350 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned char |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 348 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const char |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 346 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const char |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 344 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const char * |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 341 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const char * |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 339 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const std::string & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 336 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const std::string & |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 334 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned short |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 329 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned short |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 327 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const short |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 325 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const short |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 323 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned int |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 320 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned int |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 318 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const int |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 316 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const int |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 314 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned long |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 312 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const unsigned long |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 310 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const long |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 308 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const long |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 306 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const float |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 303 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const float |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 301 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const double |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 298 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const double |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 296 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const LoadSave & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 253 of file LoadSave.h. |
static unsigned int LoadSave::encode |
( |
const LoadSave & |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 251 of file LoadSave.h.
Referenced by encode(), SegmentedColorGenerator::encodeColors(), SegCamBehavior::openPacket(), RegionCamBehavior::openPacket(), RawCamBehavior::openPacket(), VisionObjectEvent::SaveBinaryBuffer(), TextMsgEvent::SaveBinaryBuffer(), LocomotionEvent::SaveBinaryBuffer(), EventBase::SaveBinaryBuffer(), SegmentedColorGenerator::SaveBuffer(), RLEGenerator::SaveBuffer(), RegionGenerator::SaveBuffer(), RawCameraGenerator::SaveBuffer(), JPEGGenerator::SaveBuffer(), InterleavedYUVGenerator::SaveBuffer(), FilterBankGenerator::SaveBuffer(), CDTGenerator::SaveBuffer(), BufferedImageGenerator::SaveBuffer(), saveCreator(), RawCameraGenerator::SaveFileStream(), BufferedImageGenerator::SaveFileStream(), SegCamBehavior::sendCloseConnectionPacket(), RawCamBehavior::sendCloseConnectionPacket(), and RawCamBehavior::writeColor(). |
virtual unsigned int LoadSave::getBinSize |
( |
|
) |
const [pure virtual] |
|
|
calculates space needed to save - if you can't precisely add up the size, overestimate and things will still work.
- Returns:
- number of bytes read/written, 0 if error (or empty)
Implemented in EventBase, LocomotionEvent, TextMsgEvent, VisionObjectEvent, MotionSequenceEngine, PostureEngine, WalkMC, WaypointEngine< MAX_WAY >, XMLLoadSave, BufferedImageGenerator, CDTGenerator, FilterBankGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Referenced by SaveFileStream(). |
virtual unsigned int LoadSave::LoadBuffer |
( |
const char |
buf[], |
|
|
unsigned int |
len |
|
) |
[pure virtual] |
|
|
Load from a saved buffer.
- Parameters:
-
| buf | pointer to the memory where you should begin loading |
| len | length of buf available (this isn't all yours, might be more stuff saved after yours) |
- Returns:
- the number of bytes actually used
Implemented in EventBase, MotionSequenceEngine, PostureEngine, PostureMC, WalkMC, WaypointEngine< MAX_WAY >, XMLLoadSave, BufferedImageGenerator, CDTGenerator, FilterBankGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Referenced by decode(), and LoadFileStream(). |
unsigned int LoadSave::LoadFile |
( |
const char * |
filename |
) |
[virtual] |
|
unsigned int LoadSave::LoadFileStream |
( |
FILE * |
f |
) |
[virtual] |
|
|
Used recursively on member objects once a file is already open - DON'T CLOSE the file in your overridden functions.
- Parameters:
-
| f | a pointer to the file to load |
- Warning:
- could potentially be very inefficient if root-level objects override LoadFile but leaf-level ones use this implementation, but leaf-level ones won't even get this call unless you override the ones above them - hence, this is all or nothing
- Returns:
- number of bytes read, 0 if error (or empty)
Reimplemented in EventBase, and XMLLoadSave.
Definition at line 84 of file LoadSave.cc.
Referenced by decode(), LoadFile(), and EventBase::LoadFileStream(). |
virtual unsigned int LoadSave::SaveBuffer |
( |
char |
buf[], |
|
|
unsigned int |
len |
|
) |
const [pure virtual] |
|
|
Save to a given buffer.
- Parameters:
-
| buf | pointer to the memory where you should begin writing |
| len | length of buf available. (this isn't all yours, constrain yourself to what you returned in getBinSize() ) |
- Returns:
- the number of bytes actually used
Implemented in EventBase, MotionSequenceEngine, PostureEngine, WalkMC, WaypointEngine< MAX_WAY >, XMLLoadSave, BufferedImageGenerator, CDTGenerator, FilterBankGenerator, InterleavedYUVGenerator, JPEGGenerator, RawCameraGenerator, RegionGenerator, RLEGenerator, and SegmentedColorGenerator.
Referenced by encode(), and SaveFileStream(). |
unsigned int LoadSave::saveCreator |
( |
const char * |
creator, |
|
|
FILE * |
f |
|
) |
const [virtual] |
|
|
Saves a creator code directly to a file.
- Parameters:
-
| creator | the string to use for the creator code |
| f | the file to save the code into |
- Returns:
- the number of bytes consumed
Definition at line 43 of file LoadSave.cc. |
unsigned int LoadSave::saveCreator |
( |
const char * |
creator, |
|
|
char |
buf[], |
|
|
unsigned int |
len |
|
) |
const [virtual] |
|
unsigned int LoadSave::SaveFile |
( |
const char * |
filename |
) |
const [virtual] |
|
unsigned int LoadSave::SaveFileStream |
( |
FILE * |
f |
) |
const [virtual] |
|
Member Data Documentation
|
This is the amount of extra space needed to store a string (int for len of string plus 1 for null term.
Definition at line 136 of file LoadSave.h.
Referenced by creatorSize(), decode(), encode(), TextMsgEvent::getBinSize(), SegmentedColorGenerator::getBinSize(), RLEGenerator::getBinSize(), RegionGenerator::getBinSize(), RawCameraGenerator::getBinSize(), JPEGGenerator::getBinSize(), InterleavedYUVGenerator::getBinSize(), EventBase::getBinSize(), CDTGenerator::getBinSize(), BufferedImageGenerator::getBinSize(), SegCamBehavior::sendCloseConnectionPacket(), and RawCamBehavior::sendCloseConnectionPacket(). |
The documentation for this class was generated from the following files:
|