Class datafield
For the most part, users will not need to construct a datafield. They are all
initialized as part of the datarecord when a new record is retrieved from the
database.
Constructors
#include <dataman/dataman.hh>
Create an empty datafield:
datafield::datafield(void);
construct from string, offset, length
The arguments are the charachter pointer to the string to form the datafield
from, and len is the length of the field to build. The offset and length
arguments are optional. If neither are passed, the datafield is built from
the entire string. If the offset is passed, that is where to begin a substring
to use to build the datafield. Any other length of 0 (either explicitly or
implicitly) will make a zero length datafield.
datafield::datafield(char *src, int offset, int len);
Operators
Cast operator. This will implicitly cast a datafield to a const char * for use
by those functions and operations that require it. Remember precedence rules. If
you expect
strcpy(str, master[3]+2);
to copy to str the master record field 3, from the 3rd character, that won't happen.
Because the '+' operator is overloaded as well, it will take whatever value is in
master[3] add 2 to it, then copy the contents of the result to str. What you should
do, if you want the first behavior is this:
strcpy(str, (const char *)master[3]+2);
That will cast the field to a const char *, add 2 to the address, then pass that off
to strcpy.
operator const char *() const
None of the following operators are valid to use on a blob, and all mark the datarecord
as updated.
Assignment from another field:
this makes a complete
copy of the datafield and assigns it to the destination datafield
void datafield::operator=(const datafield& d)
Assign a datafield from a character string.
Assign an entire string to a datafield. If the string is longer than the
datafield, the string will be truncated at the datafield's length. If the string
is shorter, the datafield will be left justified and blank filled.
void datafield::operator=(const char *s);
Assign a datafield from an int. If the length of the string representation of the
integer is longer than the datafield, it is truncated at that length. If it is
shorter than the datafield, it will be left justified and blank filled in the
datafield.
void datafield::operator=(const int i)
Assign a datafield from a float. If the length of the string representation of the
float is longer than the datafield, it is truncated at that length. If it is
shorter than the datafield, it will be left justified and blank filled in the
datafield
void datafield::operator=(const float f)
The 'addition' operators. A string + string is a concatanation. Adding an
int or float to a string converts the string to an int or float and performs
the operation. if the first operand is either an int or float, then convert
the second op to the appropriate op before performing the operation. If you
have two numeric datafields and wish them to be treated as an int or float, add
an integer (or float) 0 to one of them, and then perform the other operation(s).
Add two data fields according the rules above.
datafield datafield::operator+(const datafield& d)
Add (or concatenate) a string to the datafield according to the promotion
rules above.
datafield datafield::operator+(const char *s)
Add an integer to a datafield. The result in the datafield will be an
integer.
datafield datafield::operator+(const int i)
Add a float to a datafield. The result in the datafield will be a float.
datafield datafield::operator+(const float f)
Multiplication and division operators try to treat all fields numerically, either
int or float. In all cases a non-numeric value is treated as a zero.
Multiply two data fields. If a decimal is found in either of the the datafields, then both
fields are treated as floats. If no decimal is found then both are treated as an int.
datafield datafield::operator*(const datafield& f)
Multiply a numeric string to da datafield.
datafield datafield::operator*(const char * s)
Multiply an integer to a datafield. Standard type promotions apply.
datafield datafield::operator*(int i)
Multiply a float to an integer.
datafield datafield::operator*(float f)
Division of one field by another. Both datafields are converted as described
above and the division is performed. Division by zero of course is an error.
datafield datafield::operator/(const datafield& f)
Divide a datafield by a numeric string. Conversion to a float occurs only
if a decimal is found in either of the datafield or the string. Otherwise
the conversion is to an integer.
datafield datafield::operator/(const char * s)
Divide by an integer.
datafield datafield::operator/(const int i)
Divide by a float.
datafield datafield::operator/(const float f)
Method Summary
#include <dataman/dataman.hh>
There are only a few methods defined for a datafield. Others would be very easy
to implement.
Assign a blob to the field. It can't just be assigned via '=' because a blob may
be of arbritrary length. This will assign an arbritrary buffer of 'size' bytes to
a datafield. It will return a non zero value if successful, else a zero.
int datafield::put_blob(void *ptr, int len)
Copy a string to a datafield. This will assign the string to the appropriate
datafield, and return a pointer to the string contained by the datafield.
char *strcpy(datafield& d, char *s)
Copy the string representation of a datafield to a string. The pointer to the
destination is returned.
char *strcpy(char *s, datafield& d)
Copy at most i bytes from the string respresentation of a datafield to a string.
Return the pointer to the destination.
char *strncpy(char *s, datafield& d, int i)
Copy at most i bytes from a string to a datafield. If i is greater than the
length of the datafield, that is the number of bytes to copy. A pointer to the
destination string is returned.
char *strncpy(datafield& d, char *s, int i)
Concatenate the string representation of a datafield to a string.
return(strcat(s, d.getptr()));
Concatenate at most i bytes of the string representation of a datafield to a string.
a pointer to the destination string is returned.
char *strncat(char *s, datafield&d, int i)
Convert the string representation of a datafield to an integer and return the result.
int atoi(datafield& d)