Source: OmBigIntegerNode.h
|
|
|
|
#ifndef OM_BIG_INTEGER_NODE_H
#define OM_BIG_INTEGER_NODE_H
/**
* The big integer final node structure.
*
* This class provides a specialization of OmFinalNode to implement the BigInteger node construction.
* This corresponds to a sequence of digits in base 10 or 16, they are 'infinite' precision numbers.
* This is encoded as <OMI> representation </OMI>
* The list of children must always be empty.
*/
class OmBigIntegerNode : public OmFinalNode
{
public:
/**
* Constructor (can be used as default).
* @li Precondition: ~ NullPointer(digits_in) and ~ UnsupportedBase(base_in)
*/
explicit OmBigIntegerNode(const char * digits_in="", int sign_in=+1, unsigned int base_in=10) {
OmException::checkNullPointer(digits_in);
OmException::checkUnsupportedBase(base_in);
digits_ = digits_in;
sign_ = sign_in;
base_ = base_in; }
/**
* Get the digits.
*/
virtual const char * getDigits() const {
return digits_.c_str(); }
/**
* Set the digits.
* @li Precondition: ~ NullPointer(digits_in)
*/
virtual void setDigits(const char * digits_in) {
OmException::checkNullPointer(digits_in);
digits_ = digits_in; }
/**
* Get the sign.
*/
virtual int getSign() const {
return sign_; }
/**
* Set the sign.
*/
virtual void setSign(int sign_in) {
sign_ = sign_in; }
/**
* Get the base.
*/
virtual unsigned int getBase() const {
return base_; }
/**
* Set the base.
* @li Precondition: ~ UnsupportedBase(base_in)
*/
virtual void setBase(unsigned int base_in) {
base_ = base_in; }
protected:
/**
* Copy constructor.
*/
OmBigIntegerNode(const OmBigIntegerNode & other_in)
: OmFinalNode(other_in),
digits_(other_in.digits_), sign_(other_in.sign_), base_(other_in.base_) {}
/**
* Destructor.
*/
virtual ~OmBigIntegerNode() {}
/**
* Implement access to the concrete type.
*/
virtual OmType typeImp() const {
return OmBigIntegerType; }
/**
* Implement the deep cloning.
*/
virtual OmNode * cloneImp() const {
return new OmBigIntegerNode(*this); }
/**
* Implement the writing to an output device.
*/
virtual void writeImp(OmOutputDevice & output_in) const {
OmException::checkMalformedNode(digits_.empty(), "OmBigIntegerNode must have at least one digit");
output_in.writeBigInteger(digits_.c_str(), sign_, base_); }
/**
* Implement the reading from an input device.
*/
virtual void readImp(OmInputDevice & input_in) {
unsigned int length;
input_in.readLength(length);
digits_.resize(length);
input_in.readBigInteger(&digits_[0], length, sign_, base_); }
private:
string digits_;
int sign_;
unsigned int base_;
};
#endif // OM_BIG_INTEGER_NODE_H
Generated by: root@localhost.localdomain on Tue Oct 12 21:02:30 199. |