Scalar
A scalar is a variable that holds one value at a time. This section describes how to create, access, and modify scalars, along with examples.
Creating Scalars
Use new
expression.
Scalars created in the following examples are stored in ConstantSP
.
The basic data type definitions are declared in the header files
<ScalarImp.h> and <ConstantImp.h>.
ConstantSP i = new Int(1); //create a scalar of type Int with value 1
ConstantSP s = new String("DolphinDB"); //create a scalar of type String with value "DolphinDB"
ConstantSP t = new Date(2022, 11, 1); //create a scalar of type Date with value 2022.11.1
ConstantSP d = new Double(1.2); //create a scalar of type Double with value 1.2
Although header <Util.h> provides some functions that return the
corresponding pointers to create different types of scalars , it is more
recommended to use new
expression.
Accessing Scalars
To access a scalar, use the corresponding get
function. For detailed
data type mappings, see Data Types and Forms.
Note: The getString()
function can be applied to data objects
of any data type to convert their values to strings.
int ci = i->getInt();
std::string cs = s->getString();
int cd = t->getInt(); //The Date values in C++ are stored as int.
double cv = d->getDouble();
Updating Scalars
To update a scalar, use the corresponding set
function. For detailed
data type mappings, see Data Types and
Forms.
i->setInt(2);
s->setString("C++ API");
t->setInt(5000); //Number of days to January 1, 1970
d->setDouble(2.3);