MCS
0.3.3-alpha7
|
A general purpose data type. More...
#include <mcs.hh>
Public Member Functions | |
unsigned int | array (unsigned short int i1=0, unsigned short int i2=0, unsigned short int i3=0, unsigned short int i4=0, unsigned short int i5=0, unsigned short int i6=0, unsigned short int i7=0, unsigned short int i8=0, unsigned short int i9=0, unsigned short int i10=0, unsigned short int i11=0, unsigned short int i12=0, unsigned short int i13=0, unsigned short int i14=0, unsigned short int i15=0) |
Select a cell from the array. More... | |
unsigned int | arraySize () |
Return size of array. More... | |
void * | buffer () const |
Return a pointer to the internal buffer, use this at your own risk. More... | |
int | cval (char *c, int maxlength) const |
Convert internal data to a NULL terminated string and store it in a buffer. More... | |
Data () | |
Build Data object of base type STRING and length zero. More... | |
Data (const Data &from) | |
Copy constructor. Note that this will not copy any bind information. More... | |
Data (Types type, unsigned short int maxLength=0, bool isunsigned=false, string dimSpec="") | |
Constructor with specification of base type. More... | |
Data (MYSQL_BIND *bind=NULL, Types type=STRING, const char *name="", unsigned short int maxLength=0, bool isunsigned=false, unsigned int flags=0, unsigned char tag=0) | |
Constructor used to bind the object with database data. More... | |
Data (int v, unsigned char tag=0) | |
Build an object with base type INT. More... | |
Data (long long int v, unsigned char tag=0) | |
Build an object with base type BIGINT. More... | |
Data (double v, unsigned char tag=0) | |
Build an object with base type DOUBLE. More... | |
Data (string v, unsigned char tag=0) | |
Build an object with base type STRING. More... | |
Data (struct tm v, unsigned char tag=0) | |
Build an object with base type TIME. More... | |
Data (time_t v, unsigned char tag=0) | |
Build an object with base type TIME. More... | |
Data (void *lbuf, unsigned int size, unsigned char tag=0) | |
Build an object with base type BLOB. More... | |
Data (void *lbuf) | |
Build a Data object from a buffer prepared with Data.prepareBuffer(). More... | |
unsigned short int | dim (int d) |
Return length of a dimension. More... | |
double | dval () const |
Convert internal data to a double (8 bytes) floating point value. More... | |
void | emptyName () |
Set the object name to an empty string. More... | |
float | fval () const |
Convert internal data to a floating point value. More... | |
int | getDestID () |
int | getSourceID () |
unsigned char | getTag () |
Retrieve the value of the tag. More... | |
unsigned int | howManyDim () |
Return how many dimensions are in the array. More... | |
bool | isAutoIncrement () |
Tells if the database field is an auto increment field. More... | |
bool | isNull () |
Tells if no value is stored. More... | |
bool | isUnsigned () |
Tell if the object contains unsigned integers. More... | |
int | ival () const |
Convert internal data to a integer value. More... | |
unsigned short int | length () |
Return the actual length of the data in the internal buffer. More... | |
long long int | lval () const |
Convert internal data to a long long integer value. More... | |
unsigned short int | maxLength () |
Return the size of the internal buffer. More... | |
string | name () |
Return the name of the object. More... | |
unsigned int | objSize () |
Return how many bytes require the object to be serialized. More... | |
operator const char * () const | |
Wrapper cast operator to pval() More... | |
operator const double () const | |
Wrapper cast operator to dval() More... | |
operator const float () const | |
Wrapper cast operator to dval() More... | |
operator const int () const | |
Wrapper cast operator to ival() More... | |
operator const long long int () const | |
Wrapper cast operator to lval() More... | |
operator const string () const | |
Wrapper cast operator to sval() More... | |
operator const struct tm () const | |
Wrapper cast operator to tval(struct tm) More... | |
operator const time_t () const | |
Wrapper cast operator to tval() More... | |
operator const unsigned int () const | |
Wrapper cast operator to uival() More... | |
operator const unsigned long long int () const | |
Wrapper cast operator to ulval() More... | |
Data & | operator() (const int i1=0, const int i2=0, const int i3=0, const int i4=0, const int i5=0, const int i6=0, const int i7=0, const int i8=0, const int i9=0, const int i10=0, const int i11=0, const int i12=0, const int i13=0, const int i14=0, const int i15=0) |
Same as array(). More... | |
Data & | operator= (const int v) |
Wrapper assignment operator to setival(int). More... | |
Data & | operator= (const unsigned int v) |
Wrapper assignment operator to setuival(unsigned int). More... | |
Data & | operator= (const long long int v) |
Wrapper assignment operator to setlval(long long int). More... | |
Data & | operator= (const unsigned long long int v) |
Wrapper assignment operator to setulval(unsigned long long int). More... | |
Data & | operator= (const double v) |
Wrapper assignment operator to setdval(double). More... | |
Data & | operator= (const char *v) |
Wrapper assignment operator to setsval(string) More... | |
Data & | operator= (const string v) |
Wrapper assignment operator to setsval(string). More... | |
Data & | operator= (const struct tm v) |
Wrapper assignment operator to settimeval(struct tm) More... | |
Data & | operator= (const time_t v) |
Wrapper assignment operator to settimeval(time_t) More... | |
Data & | operator= (Data &d) |
To assign the value of a Data object to another Data object. More... | |
string | print () |
Returns a string representation of the object, for debug purpose. More... | |
void * | pval () const |
void | resize (string dimSpec) |
Create or resize a multi-dimensional array. More... | |
void | resizeVaryingDim (unsigned short int newsize) |
Resize variable length dimension. More... | |
void | setblob (void *lbuf, unsigned int size) |
Copy "size" bytes from the address given in "lbuf" parameter. More... | |
void | setcval (const char *v) |
Convert string value to base type and store in internal buffer. More... | |
void | setDestID (int id) |
void | setdval (double v) |
Convert double value to base type and store in internal buffer. More... | |
void | setival (int v) |
Convert int value to base type and store in internal buffer. More... | |
void | setlval (long long int v) |
Convert long int value to base type and store in internal buffer. More... | |
void | setName (string name) |
void | setNull (bool null=true) |
Set null flag. Following call to isNull() returns the value used here as parameter. More... | |
void | setpval (void *p) |
void | setSourceID (int id) |
void | setsval (string v) |
Convert string value to base type and store in internal buffer. More... | |
void | setTag (unsigned char tag) |
Set a new value to internal tag. More... | |
void | setTimeMode (enum TimeMode tm) |
void | settimenow () |
Convert current time value to base type and store in internal buffer. More... | |
void | settimeval (struct tm v) |
Convert "struct tm" value to base type and store in internal buffer. More... | |
void | settimeval (time_t v) |
Convert time_t value to base type and store in internal buffer. More... | |
void | setuival (unsigned int v) |
Convert unsigned int value to base type and store in internal buffer. More... | |
void | setulval (unsigned long long int v) |
Convert unsigned long int value to base type and store in internal buffer. More... | |
string | sval (bool addWhiteSpaces=false) const |
Convert internal data to a string object. More... | |
time_t | tval () const |
Convert internal data to a time_t value. More... | |
void | tval (struct tm *t) const |
Convert internal data to a struct tm and store it in a buffer. More... | |
Types | type () |
Return the base type of the object. More... | |
unsigned int | uival () const |
Convert internal data to an unsigned integer value. More... | |
unsigned long long int | ulval () const |
Convert internal data to an unsigned long long integer value. More... | |
unsigned int | varyingDim () |
Return the index of the dimension that may vary. More... | |
~Data () | |
Destructor Frees internal buffer. More... | |
![]() | |
void * | getEntireBuffer (unsigned int &size) |
bool | knowSize () |
Reinitialize internal data. More... | |
unsigned int | maxChunkSize () |
Return the max size allowed for a chunk. More... | |
unsigned int | nChunk () |
If knowSize() is true, return how many chunks are required to send all data. More... | |
void * | nextChunk (unsigned int &chunksize) |
Fills a buffer with next chunk to be sent. More... | |
Serializable & | operator= (const Serializable &) |
Declared to avoid using of default assignment operator. More... | |
Serializable (const Serializable &) | |
Declared to avoid using of default copy constructor. More... | |
Serializable (unsigned int lmaxChunksize=16384) | |
Constructor, for custom data (type = SERIAL_UNKNOWN). More... | |
Serializable (void *from, unsigned int size, bool freeAfterUse, unsigned int lmaxChunksize=16384) | |
Constructor, for memory buffers (type = SERIAL_BUFFER). More... | |
Serializable (string filename, unsigned int lmaxChunksize=16384) | |
Constructor, for files (type = SERIAL_FILENAME). More... | |
Serializable (int type, unsigned int lmaxChunksize=16384) | |
unsigned int | size () |
If knowSize() is true, return the size of the entire block of data. More... | |
virtual | ~Serializable () |
Destructor. More... | |
Static Public Member Functions | |
static long long int | MaxValue (Types ltype, bool flunsigned) |
Return the maximum integer value for the base type specified. More... | |
static long long int | MinValue (Types ltype, bool flunsigned) |
Return the minimum integer value for the base type specified. More... | |
static void | parseTime (string s, struct tm *ts) |
Fills the "struct tm*" passed as argument with the current local datetime. More... | |
Private Member Functions | |
void | init (MYSQL_BIND *bind, Types type, const char *name="", unsigned short int maxLength=0, bool isunsigned=false, unsigned int flags=0) |
Initialize internal structures. More... | |
void | reallocBuffer () |
bool | serialize_buffer (char *&from, unsigned int &size) |
Prepare a buffer with all informations contained in the object. More... | |
Private Attributes | |
unsigned int | arrpos |
Last selected array cell. More... | |
unsigned int | arrsize |
Array size, i.e. how many cells are in the array. More... | |
char * | buf |
Data buffer. More... | |
unsigned int | bufsize |
Size of data buffer. More... | |
DateTime | dt |
int | id_dest |
The userid of the thread that will receive this object. More... | |
int | id_source |
The userid of the thread who send this object. More... | |
bool | lautoincr |
If the AUTO_INCREMENT flag is true. More... | |
MYSQL_BIND * | lbind |
Internal reference to MYSQL_BIND structure. More... | |
unsigned short int | ldim [15] |
Size of each dimension. More... | |
unsigned char | ldimspec |
Multi-dimensional array specification. More... | |
unsigned int | lflags |
Flags (EXPERIMENTAL). More... | |
my_bool | lisnull |
The object has a null value. More... | |
bool | lisunsigned |
Base type is unsigned. More... | |
unsigned long | llength |
Actual length of real data in the buffer, useful only when the base type is a variable length type. More... | |
unsigned short int | lmaxlength |
Max number of bytes that can be stored in the buffer (size of the buffer). More... | |
string | lname |
Object name. More... | |
Types | ltype |
Object base type. More... | |
MCS_DEBUG_ALLOC | |
unsigned short int | mult [15] |
Multiplicative coefficients to calculate arrpos. More... | |
unsigned char | tag |
Tag for user convenience. More... | |
Static Private Attributes | |
static const char * | dafmt = "%04d-%02d-%02d" |
Format to handle date in sprintf/sscanf calls. More... | |
static const char * | dfmt = "%lf" |
Format to handle double float in sprintf/sscanf calls. More... | |
static const char * | dtfmt = "%04d-%02d-%02d %02d:%02d:%02g" |
Format to handle datetime in sprintf/sscanf calls. More... | |
static const char * | ffmt = "%f" |
Format to handle float in sprintf/sscanf calls. More... | |
static const char * | ifmt = "%d" |
Format to handle integers in sprintf/sscanf calls. More... | |
static const char * | lfmt = "%ld" |
Format to handle long integers in sprintf/sscanf calls. More... | |
static const char * | tmfmt = "%02d:%02d:%02g" |
Format to handle time in sprintf/sscanf calls. More... | |
A general purpose data type.
This class let you create a high-level object that has its own base type, but is able to perform conversion to a different data type. Available base types are those of the mcs::Types enumeration, namely: integers, floating point, string, char*, struct tm*, time_t, memory buffers and pointers. Some base types (STRING, TINY_BLOB and BLOB) are variable length objects, that is their length varies between zero and a maximum specified in the constructor. All other base types are fixed length objects. All integer types can be either signed or unsigned. Conversion between different types follow standard rules (described below). If the conversion cannot be performed an exception is thrown.
This class is widely used inside MCS code due to its ease of use. Some examples follows:
The Data class features several constructors to allow writing "easy to read" code as well as several methods to perform conversion to/from any allowed data types (see all *val, and set*val methods). Also several assignment operators wraps the set*val methods. Furthermore a Data object can contain either a single value (scalar) or a multi-dimensional array of the same base data type values (see resize(), array(), dim()).
Each Data object has auxiliary informations:
The Data object can be used to access value of a database table, in this case the isAutoIncrement() and isNull() methods provide further information about the underlying database field.
Finally, the Data class extends the Serialize class so it can be serialized to be sent through the network or saved on disk.
mcs::Data::Data | ( | ) |
mcs::Data::Data | ( | const Data & | from | ) |
mcs::Data::Data | ( | Types | type, |
unsigned short int | maxLength = 0 , |
||
bool | isunsigned = false , |
||
string | dimSpec = "" |
||
) |
Constructor with specification of base type.
With this constructor the object will have the base type specified in the parameters but won't have any value stored in the internal buffer, and no bind informations.
type | Base type for the object; |
maxLength | Max length of the object if "type" is a variable length type; |
isunsigned | Unsigned flag of the object, default is false (so that the data is signed); |
mcs::Data::Data | ( | MYSQL_BIND * | bind = NULL , |
Types | type = STRING , |
||
const char * | name = "" , |
||
unsigned short int | maxLength = 0 , |
||
bool | isunsigned = false , |
||
unsigned int | flags = 0 , |
||
unsigned char | tag = 0 |
||
) |
Constructor used to bind the object with database data.
bind | A bind structure address, retrieved from a Query object. It can be NULL, if the object is not intended for db use; |
type | Base type for the object; |
name | Name of the object, this can be NULL for all practical use, it becomes important when the object is created inside a Query object because you can specifiy the name of a parameter or a field instead of its positional index; |
maxLength | Size of internal buffer when base type is STRING; |
isunsigned | Unsigned flag of the object, default is false (so that the data is signed); |
flags | Database flags for the field; |
tag | Set a new value to internal tag. |
mcs::Data::Data | ( | int | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | long long int | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | double | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | string | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | struct tm | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | time_t | v, |
unsigned char | tag = 0 |
||
) |
mcs::Data::Data | ( | void * | lbuf, |
unsigned int | size, | ||
unsigned char | tag = 0 |
||
) |
Build an object with base type BLOB.
The max length is given by the parameter "size". This constructor also copies "size" bytes from the source "lbuf" to the internal buffer.
lbuf | Pointer to the buffer in memory. |
size | Size of the BLOB. |
tag | Optional tag for the object. |
mcs::Data::Data | ( | void * | lbuf | ) |
unsigned int mcs::Data::array | ( | unsigned short int | i1 = 0 , |
unsigned short int | i2 = 0 , |
||
unsigned short int | i3 = 0 , |
||
unsigned short int | i4 = 0 , |
||
unsigned short int | i5 = 0 , |
||
unsigned short int | i6 = 0 , |
||
unsigned short int | i7 = 0 , |
||
unsigned short int | i8 = 0 , |
||
unsigned short int | i9 = 0 , |
||
unsigned short int | i10 = 0 , |
||
unsigned short int | i11 = 0 , |
||
unsigned short int | i12 = 0 , |
||
unsigned short int | i13 = 0 , |
||
unsigned short int | i14 = 0 , |
||
unsigned short int | i15 = 0 |
||
) |
unsigned int mcs::Data::arraySize | ( | ) |
void * mcs::Data::buffer | ( | ) | const |
int mcs::Data::cval | ( | char * | c, |
int | maxlength | ||
) | const |
Convert internal data to a NULL terminated string and store it in a buffer.
c | Address of the buffer. |
maxlength | Max number of bytes that can be copied in the buffer. |
unsigned short int mcs::Data::dim | ( | int | d | ) |
double mcs::Data::dval | ( | ) | const |
void mcs::Data::emptyName | ( | ) |
float mcs::Data::fval | ( | ) | const |
unsigned char mcs::Data::getTag | ( | ) |
unsigned int mcs::Data::howManyDim | ( | ) |
|
private |
bool mcs::Data::isAutoIncrement | ( | ) |
bool mcs::Data::isUnsigned | ( | ) |
int mcs::Data::ival | ( | ) | const |
unsigned short int mcs::Data::length | ( | ) |
long long int mcs::Data::lval | ( | ) | const |
unsigned short int mcs::Data::maxLength | ( | ) |
|
static |
|
static |
Return the minimum integer value for the base type specified.
ltype | Base type for which compute the min value. |
flunsigned | If the value should be considered unsigned. |
If flunsigned is false this function always returns zero.
unsigned int mcs::Data::objSize | ( | ) |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Data & mcs::Data::operator() | ( | const int | i1 = 0 , |
const int | i2 = 0 , |
||
const int | i3 = 0 , |
||
const int | i4 = 0 , |
||
const int | i5 = 0 , |
||
const int | i6 = 0 , |
||
const int | i7 = 0 , |
||
const int | i8 = 0 , |
||
const int | i9 = 0 , |
||
const int | i10 = 0 , |
||
const int | i11 = 0 , |
||
const int | i12 = 0 , |
||
const int | i13 = 0 , |
||
const int | i14 = 0 , |
||
const int | i15 = 0 |
||
) |
|
inline |
Wrapper assignment operator to setival(int).
|
inline |
Wrapper assignment operator to setuival(unsigned int).
|
inline |
Wrapper assignment operator to setlval(long long int).
|
inline |
Wrapper assignment operator to setulval(unsigned long long int).
|
inline |
Wrapper assignment operator to setdval(double).
|
inline |
Wrapper assignment operator to setsval(string)
|
inline |
Wrapper assignment operator to setsval(string).
|
inline |
Wrapper assignment operator to settimeval(struct tm)
|
inline |
Wrapper assignment operator to settimeval(time_t)
To assign the value of a Data object to another Data object.
This operator is used to copy the value of a Data object to another Data object. Note that, as in any other use of the assignment operator, only the value is copied, not all the other settings of a Data object. This operator will be called each time you assign a Data object to another Data object. In the particular cas in which you are creating a Data object with an assignment the copy constructor will be called instead of this.
|
static |
Fills the "struct tm*" passed as argument with the current local datetime.
Parse string to extract date time information.
The date time format must be one of: YYYY-MM-DD HH:MM:SS YYYY-MM-DD HH:MM:SS otherwise an exception will be thrown.
s | String to be parsed. |
ts | Address of a struct tm that will be filled with parsed information. |
ERROR | MSG_CONVERSION_DATETIME. |
string mcs::Data::print | ( | ) |
void mcs::Data::resize | ( | string | dimSpec | ) |
Create or resize a multi-dimensional array.
The array can have as much as MCS_DATA_NDIM dimensions (actually 15), and each dimension can have as much as 65535 positions.
When you call this method you must specify:
All this informations are given in a string formatted using the VOTable specifications (http://www.ivoa.net/Documents/latest/VOT.html) for the "arraysize" attribute of a "FIELD" node.
Some examples are:
void mcs::Data::resizeVaryingDim | ( | unsigned short int | newsize | ) |
Resize variable length dimension.
If a dimension is allowed to vary in length (see resize()) you can change its length with this method. If you increase the size of the dimension then all values already present in the array will be preserved and new values will be set to zeroes.
If no dimension is allowed to vary then an exception will be thrown.
|
privatevirtual |
Prepare a buffer with all informations contained in the object.
Once the buffer is prepared you can rebuild an identical object (except for the bind information) using the Data(void*) cosntructor.
If "*lbuf" is NULL then the buffer will be allocated, otherwise "size" must be set to the length of the buffer pointed by "*lbuf";
lbuf | Address of a pointer to a buffer; |
size | Size of the buffer if it should not be allocated. |
ERROR | MSG_NOT_ENOUGH_SPACE. |
Reimplemented from mcs::Serializable.
void mcs::Data::setblob | ( | void * | lbuf, |
unsigned int | size | ||
) |
void mcs::Data::setcval | ( | const char * | v | ) |
void mcs::Data::setdval | ( | double | v | ) |
void mcs::Data::setival | ( | int | v | ) |
void mcs::Data::setlval | ( | long long int | v | ) |
void mcs::Data::setNull | ( | bool | null = true | ) |
void mcs::Data::setsval | ( | string | v | ) |
void mcs::Data::setTag | ( | unsigned char | tag | ) |
void mcs::Data::settimenow | ( | ) |
void mcs::Data::settimeval | ( | struct tm | v | ) |
Convert "struct tm" value to base type and store in internal buffer.
void mcs::Data::settimeval | ( | time_t | v | ) |
void mcs::Data::setuival | ( | unsigned int | v | ) |
void mcs::Data::setulval | ( | unsigned long long int | v | ) |
string mcs::Data::sval | ( | bool | addWhiteSpaces = false | ) | const |
time_t mcs::Data::tval | ( | ) | const |
void mcs::Data::tval | ( | struct tm * | t | ) | const |
Types mcs::Data::type | ( | ) |
unsigned int mcs::Data::uival | ( | ) | const |
unsigned long long int mcs::Data::ulval | ( | ) | const |
unsigned int mcs::Data::varyingDim | ( | ) |
Return the index of the dimension that may vary.
The last dimension of the multi-dimensional array may vary in length (see resizeVaryingDim()) if it is allowed to do so. This method returns the index of the dimension which is allowed to vary in the 1..MCS_DATA_NDIM range, or 0 if no dimension can change.
|
private |
|
private |
|
private |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
|
private |
|
private |
|
private |
|
private |
|
private |
|
staticprivate |
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha7
|