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 107 of file LoadSave.h.
|
Public Member Functions |
|
| LoadSave () |
| constructor
|
| LoadSave (const char *filename) |
| 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 |
|
encode/decode cross-platform compatable (byte order consistancy)
|
unsigned int | encode (const LoadSave &x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (LoadSave &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const LoadSave &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (LoadSave &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const double x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (double &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const double x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (double &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const float x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (float &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const float x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (float &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const long x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (long &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const long x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (long &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned long x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned long &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned long x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned long &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const int x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (int &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const int x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (int &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned int x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned int &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned int x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned int &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const short x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (short &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const short x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (short &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned short x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned short &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned short x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned short &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const std::string &x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (std::string &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const std::string &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (std::string &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const char *x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (char *&x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const char *x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (char *&x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const char x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (char &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const char x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (char &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned char x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned char &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const unsigned char x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (unsigned char &x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const bool x, char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | decode (bool &x, const char buf[], unsigned int cap) |
| encode or decode with byte order consistancy
|
unsigned int | encode (const bool x, FILE *f) |
| encode or decode with byte order consistancy
|
unsigned int | decode (bool &x, FILE *f) |
| encode or decode with byte order consistancy
|
Static Public Attributes |
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> 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 |
( |
const char * |
filename |
) |
[inline] |
|
Member Function Documentation
template<class T> |
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 318 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] |
|
virtual unsigned int LoadSave::creatorSize |
( |
const char |
creator[] |
) |
const [inline, virtual] |
|
unsigned int LoadSave::decode |
( |
bool & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 314 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
bool & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 312 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
unsigned char & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 309 of file LoadSave.h. |
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 307 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
char & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 305 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
char & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 303 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
char *& |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 300 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
char *& |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 298 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
std::string & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 295 of file LoadSave.h. |
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 293 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
unsigned short & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 288 of file LoadSave.h. |
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 286 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
short & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 284 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
short & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 282 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
unsigned int & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 279 of file LoadSave.h. |
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 277 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
int & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 275 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
int & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 273 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
unsigned long & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 271 of file LoadSave.h. |
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 269 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
long & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 267 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
long & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 265 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
float & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 262 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
float & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 260 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
double & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 257 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
double & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 255 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
LoadSave & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 209 of file LoadSave.h. |
unsigned int LoadSave::decode |
( |
LoadSave & |
x, |
|
|
const char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 207 of file LoadSave.h.
Referenced by checkCreator(), decode(), SegmentedColorGenerator::decodeColors(), VisionObjectEvent::LoadBuffer(), TextMsgEvent::LoadBuffer(), SegmentedColorGenerator::LoadBuffer(), RLEGenerator::LoadBuffer(), RegionGenerator::LoadBuffer(), RawCameraGenerator::LoadBuffer(), LocomotionEvent::LoadBuffer(), JPEGGenerator::LoadBuffer(), InterleavedYUVGenerator::LoadBuffer(), FilterBankGenerator::LoadBuffer(), and EventBase::LoadBuffer(). |
unsigned int LoadSave::encode |
( |
const bool |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 313 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const bool |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 311 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const unsigned char |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 308 of file LoadSave.h. |
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 306 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const char |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 304 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const char |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 302 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const char * |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 299 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const char * |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 297 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const std::string & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 294 of file LoadSave.h. |
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 292 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const unsigned short |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 287 of file LoadSave.h. |
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 285 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const short |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 283 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const short |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 281 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const unsigned int |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 278 of file LoadSave.h. |
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 276 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const int |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 274 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const int |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 272 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const unsigned long |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 270 of file LoadSave.h. |
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 268 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const long |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 266 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const long |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 264 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const float |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 261 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const float |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 259 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const double |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 256 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const double |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 254 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const LoadSave & |
x, |
|
|
FILE * |
f |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 208 of file LoadSave.h. |
unsigned int LoadSave::encode |
( |
const LoadSave & |
x, |
|
|
char |
buf[], |
|
|
unsigned int |
cap |
|
) |
[inline, static] |
|
|
encode or decode with byte order consistancy
Definition at line 206 of file LoadSave.h.
Referenced by encode(), SegmentedColorGenerator::encodeColors(), SegCamBehavior::openPacket(), RawCamBehavior::openPacket(), VisionObjectEvent::SaveBuffer(), TextMsgEvent::SaveBuffer(), SegmentedColorGenerator::SaveBuffer(), RLEGenerator::SaveBuffer(), RegionGenerator::SaveBuffer(), RawCameraGenerator::SaveBuffer(), LocomotionEvent::SaveBuffer(), JPEGGenerator::SaveBuffer(), InterleavedYUVGenerator::SaveBuffer(), FilterBankGenerator::SaveBuffer(), EventBase::SaveBuffer(), CDTGenerator::SaveBuffer(), saveCreator(), RawCameraGenerator::SaveFileStream(), 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, MotionSequence, PostureEngine, WalkMC, 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, LocomotionEvent, TextMsgEvent, VisionObjectEvent, MotionSequence, PostureEngine, PostureMC, WalkMC, 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)
Definition at line 84 of file LoadSave.cc.
Referenced by decode(), and LoadFile(). |
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, LocomotionEvent, TextMsgEvent, VisionObjectEvent, MotionSequence, PostureEngine, WalkMC, 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] |
|
|
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 save |
- Warning:
- could potentially be very inefficient if root-level objects override SaveFile 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 written, 0 if error (or empty)
Reimplemented in RawCameraGenerator.
Definition at line 114 of file LoadSave.cc.
Referenced by encode(), CameraBehavior::processEvent(), and SaveFile(). |
Member Data Documentation
The documentation for this class was generated from the following files:
|