Library to allo USB PTP device to be hosted by the mbed platform
Dependents: class_project_main
Diff: PIMA15740/PIMAString.h
- Revision:
- 0:98cf19bcd828
- Child:
- 1:71c0e9dc153d
diff -r 000000000000 -r 98cf19bcd828 PIMA15740/PIMAString.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PIMA15740/PIMAString.h Fri Aug 23 00:52:52 2013 +0000 @@ -0,0 +1,63 @@ + +#include "mallocdebug.h" + +class PIMAString { +public: + + PIMAString() { + length=0; + StringChars=NULL; + vals=NULL; + }; + + ~PIMAString() { + if( StringChars !=NULL) + free(StringChars); + if(vals!=NULL) + free(vals); + }; + + int FillString(uint8_t *currentPtr) { + setLength(*currentPtr); + setStringChars((uint16_t *)(currentPtr+1)); + return 2*length +1; + }; + + + char * getString() { + if(vals!=NULL) + free(vals); + vals=(char *) malloc(sizeof(char)*(this->length+1)); + for(int i=0;i<this->length;i++) + vals[i]=StringChars[i]; //NOTE: Truncates the uint16_t value. + vals[length]='\0'; + return vals; + } + + uint8_t getLength() { + return this->length; + } + + private: + void setLength(uint8_t length) { + if(length > this->length) { + if( StringChars !=NULL) + free(StringChars); + StringChars = (uint16_t *) malloc(sizeof(uint16_t)*length); + } + this->length=length; + + }; + + void setStringChars(uint16_t *buffer){ + if(buffer!=NULL && StringChars !=NULL) + for(int i=0;i<this->length;i++) + StringChars[i]=buffer[i]; + }; + + + uint8_t length; + uint16_t *StringChars; + char *vals; + +}; \ No newline at end of file