# OTL 4.0, Template otl_value<T>

# Template otl_value<T>

This is an OTL template class which allows the user to create a derivative data container based upon the following scalar data types: int, unsigned, long, short, float, double, otl_datetime (OTL date&time container), std::string (STL string class).

The derivative container has built-in NULL indicator functionality, that is, the containter has a NULL indicator field in it and can carry over the NULL value from one operation to another.

For example, a value gets read from a SELECT statement into a otl_value<int> container, and, it is a NULL. Then, the same value gets written into an INSERT statement. The otl_value<int> container retains the NULL in its NULL indicator field, and the NULL gets carried over from the SELECT into the INSERT.

The otl_value<T> class can be activated with #define OTL_STL, or #define OTL_VALUE_TEMPLATE_ON.

    template<class TData>
    class otl_value{
    public:

- Data members of the class. v is a container for a scalar value of the TData type. ind is a NULL indicator. These fields can be used directly or indirectly, via copy constructors assignment operators (see below)

         TData v;
         bool ind;

- Constructors, operators, and functions

         otl_value(); // default constructor

         otl_value(const otl_value<TData>& var); // copy constructor
         otl_value(const TData& var); // copy constructor
         otl_value(const otl_null& var); // copy constructor

         otl_value<TData>& operator=(const otl_value<TData>& var); //assignment operator
         otl_value<TData>& operator=(const TData& var); // assignment operator
         otl_value<TData>& operator=(const otl_null& var); // assignment operator

         bool is_null(void) const; // function which returns true if the otl_value is NULL

         void set_null(void); // function which sets the otl_value to NULL.
                              // This function duplicates the assignment
                              // operator=(const otl_null&), and used only
                              // when .v and/or .ind fields
                              // are used directly

         void set_non_null(void); // function which sets the otl_value to "non-NULL",
                                  // and should be used only when .v and/or .ind fields
                                  // are used directly.

    }; // end of otl_value

Also, two global global template stream operators were overloaded for otl_value<T> and otl_stream's:

    template <class TData>
    otl_stream& operator<<(otl_stream& s, const otl_value<TData>& var);

    template <class TData>
    otl_stream& operator>>(otl_stream& s, otl_value<TData>& var);

These two template overloaded operators can be used in a combination with the otl_value<T> container. The operators carry over NULL values, if there are any.

Here's one more overloaded operator<< for writing otl_value<T>'s to std::ostream:

    template <class TData> std::ostream&
    operator<<(std::ostream& s, const otl_value<TData>& var);

Prev Next Contents Go Home

Copyright © 1996, 2007, Sergei Kuchin, email: skuchin@ispwest.com, skuchin@gmail.com
.

Permission to use, copy, modify and redistribute this document for any purpose is hereby granted without fee, provided that the above copyright notice appear in all copies.