LCOV - code coverage report
Current view: top level - libdbproxy - value.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 35 0.0 %
Date: 2019-12-15 17:13:15 Functions: 0 21 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  * Header:
       3             :  *      libsnapwebsites/src/libdbproxy/value.h
       4             :  *
       5             :  * Description:
       6             :  *      Handling of a cell value to access data within the Cassandra database.
       7             :  *
       8             :  * Documentation:
       9             :  *      See the corresponding .cpp file.
      10             :  *
      11             :  * License:
      12             :  *      Copyright (c) 2011-2019  Made to Order Software Corp.  All Rights Reserved
      13             :  * 
      14             :  *      https://snapwebsites.org/
      15             :  *      contact@m2osw.com
      16             :  * 
      17             :  *      Permission is hereby granted, free of charge, to any person obtaining a
      18             :  *      copy of this software and associated documentation files (the
      19             :  *      "Software"), to deal in the Software without restriction, including
      20             :  *      without limitation the rights to use, copy, modify, merge, publish,
      21             :  *      distribute, sublicense, and/or sell copies of the Software, and to
      22             :  *      permit persons to whom the Software is furnished to do so, subject to
      23             :  *      the following conditions:
      24             :  *
      25             :  *      The above copyright notice and this permission notice shall be included
      26             :  *      in all copies or substantial portions of the Software.
      27             :  *
      28             :  *      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      29             :  *      OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
      30             :  *      MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
      31             :  *      IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
      32             :  *      CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
      33             :  *      TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
      34             :  *      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
      35             :  */
      36             : #pragma once
      37             : 
      38             : #include "libdbproxy/consistency_level.h"
      39             : 
      40             : #include <cassvalue/encoder.h>
      41             : #include <cassvalue/value.h>
      42             : 
      43             : #include <QString>
      44             : #include <QByteArray>
      45             : 
      46             : #include <execinfo.h>
      47             : #include <stdint.h>
      48             : 
      49             : #include <iostream>
      50             : #include <memory>
      51             : 
      52             : namespace libdbproxy
      53             : {
      54             : 
      55             : /*******************************************************************************
      56             :  * Light wrappers around the functions and classes in the cassvalue library
      57             :  *******************************************************************************/
      58             : 
      59             : inline uint64_t getBufferMaxSize()
      60             : {
      61             :     return cassvalue::getBufferMaxSize();
      62             : }
      63             : 
      64             : 
      65             : inline void checkBufferSize(const uint64_t new_size)
      66             : {
      67             :     return cassvalue::checkBufferSize(new_size);
      68             : }
      69             : 
      70             : // Null
      71             : inline void setNullValue(QByteArray& array)
      72             : {
      73             :     cassvalue::setNullValue(array);
      74             : }
      75             : 
      76             : // Bool
      77             : inline void appendBoolValue(QByteArray& array, const bool value)
      78             : {
      79             :     cassvalue::appendBoolValue(array,value);
      80             : }
      81             : 
      82             : inline void setBoolValue(QByteArray& array, const bool value)
      83             : {
      84             :     cassvalue::setBoolValue(array,value);
      85             : }
      86             : 
      87             : inline bool boolValue(const QByteArray& array, const int index = 0)
      88             : {
      89             :     return cassvalue::boolValue(array,index);
      90             : }
      91             : 
      92             : inline bool boolValueOrNull(const QByteArray& array, const int index = 0, const bool default_value = false)
      93             : {
      94             :     return cassvalue::boolValueOrNull(array,index,default_value);
      95             : }
      96             : 
      97             : // Char
      98             : inline void appendCharValue(QByteArray& array, const char value)
      99             : {
     100             :     cassvalue::appendCharValue(array,value);
     101             : }
     102             : 
     103             : inline void setCharValue(QByteArray& array, const char value)
     104             : {
     105             :     cassvalue::setCharValue(array,value);
     106             : }
     107             : 
     108             : inline char charValue(const QByteArray& array, const int index = 0)
     109             : {
     110             :     return cassvalue::charValue(array,index);
     111             : }
     112             : 
     113             : inline char charValueOrNull(const QByteArray& array, const int index = 0, const char default_value = 0)
     114             : {
     115             :     return cassvalue::charValueOrNull(array,index,default_value);
     116             : }
     117             : 
     118             : inline char safeCharValue(const QByteArray& array, const int index = 0, const char default_value = 0)
     119             : {
     120             :     return cassvalue::safeCharValue(array,index,default_value);
     121             : }
     122             : 
     123             : inline void appendSignedCharValue(QByteArray& array, const signed char value)
     124             : {
     125             :     cassvalue::appendCharValue(array, value);
     126             : }
     127             : 
     128             : inline void setSignedCharValue(QByteArray& array, const signed char value)
     129             : {
     130             :     cassvalue::setCharValue(array, value);
     131             : }
     132             : 
     133             : inline signed char signedCharValue(const QByteArray& array, const int index = 0)
     134             : {
     135             :     return cassvalue::signedCharValue(array,index);
     136             : }
     137             : 
     138             : inline signed char signedCharValueOrNull(const QByteArray& array, const int index = 0, const signed char default_value = 0)
     139             : {
     140             :     return cassvalue::signedCharValueOrNull(array,index,default_value);
     141             : }
     142             : 
     143             : inline signed char safeSignedCharValue(const QByteArray& array, const int index = 0, const signed char default_value = 0)
     144             : {
     145             :     return cassvalue::safeSignedCharValue(array,index,default_value);
     146             : }
     147             : 
     148           0 : inline void appendUnsignedCharValue(QByteArray& array, const unsigned char value)
     149             : {
     150           0 :     cassvalue::appendCharValue(array, value);
     151           0 : }
     152             : 
     153             : inline void setUnsignedCharValue(QByteArray& array, const unsigned char value)
     154             : {
     155             :     cassvalue::setCharValue(array, value);
     156             : }
     157             : 
     158             : inline unsigned char unsignedCharValue(const QByteArray& array, const int index = 0)
     159             : {
     160             :     return cassvalue::unsignedCharValue(array,index);
     161             : }
     162             : 
     163             : inline unsigned char unsignedCharValueOrNull(const QByteArray& array, const int index = 0, const unsigned char default_value = 0)
     164             : {
     165             :     return cassvalue::unsignedCharValueOrNull(array,index,default_value);
     166             : }
     167             : 
     168           0 : inline unsigned char safeUnsignedCharValue(const QByteArray& array, const int index = 0, const unsigned char default_value = 0)
     169             : {
     170           0 :     return cassvalue::safeUnsignedCharValue(array,index,default_value);
     171             : }
     172             : 
     173             : // Int16
     174             : inline void appendInt16Value(QByteArray& array, const int16_t value)
     175             : {
     176             :     cassvalue::appendInt16Value(array,value);
     177             : }
     178             : 
     179             : inline void setInt16Value(QByteArray& array, const int16_t value)
     180             : {
     181             :     cassvalue::setInt16Value(array,value);
     182             : }
     183             : 
     184             : inline int16_t int16Value(const QByteArray& array, const int index = 0)
     185             : {
     186             :     return cassvalue::int16Value(array,index);
     187             : }
     188             : 
     189             : inline int16_t int16ValueOrNull(const QByteArray& array, const int index = 0, const int16_t default_value = 0)
     190             : {
     191             :     return cassvalue::int16ValueOrNull(array,index,default_value);
     192             : }
     193             : 
     194             : inline int16_t safeInt16Value(const QByteArray& array, const int index = 0, const int16_t default_value = 0)
     195             : {
     196             :     return cassvalue::safeInt16Value(array,index,default_value);
     197             : }
     198             : 
     199             : inline void appendUInt16Value(QByteArray& array, const uint16_t value)
     200             : {
     201             :     cassvalue::appendInt16Value(array, value);
     202             : }
     203             : 
     204             : inline void setUInt16Value(QByteArray& array, const uint16_t value)
     205             : {
     206             :     cassvalue::setInt16Value(array, value);
     207             : }
     208             : 
     209             : inline uint16_t uint16Value(const QByteArray& array, const int index = 0)
     210             : {
     211             :     return cassvalue::uint16Value(array,index);
     212             : }
     213             : 
     214             : inline uint16_t uint16ValueOrNull(const QByteArray& array, const int index = 0, const uint16_t default_value = 0)
     215             : {
     216             :     return cassvalue::uint16ValueOrNull(array,index,default_value);
     217             : }
     218             : 
     219             : inline uint16_t safeUInt16Value(const QByteArray& array, const int index = 0, const uint16_t default_value = 0)
     220             : {
     221             :     return cassvalue::safeUInt16Value(array,index,default_value);
     222             : }
     223             : 
     224             : // Int32
     225             : inline void appendInt32Value(QByteArray& array, const int32_t value)
     226             : {
     227             :     cassvalue::appendInt32Value(array,value);
     228             : }
     229             : 
     230             : inline void setInt32Value(QByteArray& array, const int32_t value)
     231             : {
     232             :     cassvalue::setInt32Value(array,value);
     233             : }
     234             : 
     235             : inline void replaceInt32Value(QByteArray& array, const int32_t value, const int index = 0)
     236             : {
     237             :     return cassvalue::replaceInt32Value(array,value,index);
     238             : }
     239             : 
     240           0 : inline int32_t int32Value(const QByteArray& array, const int index = 0)
     241             : {
     242           0 :     return cassvalue::int32Value(array,index);
     243             : }
     244             : 
     245             : inline int32_t int32ValueOrNull(const QByteArray& array, const int index = 0, const int32_t default_value = 0)
     246             : {
     247             :     return cassvalue::int32ValueOrNull(array,index,default_value);
     248             : }
     249             : 
     250             : inline int32_t safeInt32Value(const QByteArray& array, const int index = 0, const int32_t default_value = 0)
     251             : {
     252             :     return cassvalue::safeInt32Value(array,index,default_value);
     253             : }
     254             : 
     255           0 : inline void appendUInt32Value(QByteArray& array, const uint32_t value)
     256             : {
     257           0 :     cassvalue::appendInt32Value(array, value);
     258           0 : }
     259             : 
     260             : inline void setUInt32Value(QByteArray& array, const uint32_t value)
     261             : {
     262             :     cassvalue::setInt32Value(array, value);
     263             : }
     264             : 
     265             : inline void replaceUInt32Value(QByteArray& array, const uint32_t value, const int index = 0)
     266             : {
     267             :     cassvalue::replaceInt32Value(array, value, index);
     268             : }
     269             : 
     270             : inline uint32_t uint32Value(const QByteArray& array, const int index = 0)
     271             : {
     272             :     return cassvalue::uint32Value(array,index);
     273             : }
     274             : 
     275             : inline uint32_t uint32ValueOrNull(const QByteArray& array, const int index = 0, const uint32_t default_value = 0)
     276             : {
     277             :     return cassvalue::uint32ValueOrNull(array,index,default_value);
     278             : }
     279             : 
     280           0 : inline uint32_t safeUInt32Value(const QByteArray& array, const int index = 0, const uint32_t default_value = 0)
     281             : {
     282           0 :     return cassvalue::safeUInt32Value(array,index,default_value);
     283             : }
     284             : 
     285             : // Int64
     286           0 : inline void appendInt64Value(QByteArray& array, const int64_t value)
     287             : {
     288           0 :     cassvalue::appendInt64Value(array,value);
     289           0 : }
     290             : 
     291           0 : inline void setInt64Value(QByteArray& array, const int64_t value)
     292             : {
     293           0 :     cassvalue::setInt64Value(array,value);
     294           0 : }
     295             : 
     296             : inline int64_t int64Value(const QByteArray& array, const int index = 0)
     297             : {
     298             :     return cassvalue::int64Value(array,index);
     299             : }
     300             : 
     301             : inline int64_t int64ValueOrNull(const QByteArray& array, const int index = 0, const int64_t default_value = 0)
     302             : {
     303             :     return cassvalue::int64ValueOrNull(array,index,default_value);
     304             : }
     305             : 
     306           0 : inline int64_t safeInt64Value(const QByteArray& array, const int index = 0, const int64_t default_value = 0)
     307             : {
     308           0 :     return cassvalue::safeInt64Value(array,index,default_value);
     309             : }
     310             : 
     311             : inline void appendUInt64Value(QByteArray& array, const uint64_t value)
     312             : {
     313             :     cassvalue::appendInt64Value(array, value);
     314             : }
     315             : 
     316             : inline void setUInt64Value(QByteArray& array, const uint64_t value)
     317             : {
     318             :     cassvalue::setInt64Value(array, value);
     319             : }
     320             : 
     321             : inline uint64_t uint64Value(const QByteArray& array, const int index = 0)
     322             : {
     323             :     return cassvalue::uint64Value(array,index);
     324             : }
     325             : 
     326             : inline uint64_t uint64ValueOrNull(const QByteArray& array, const int index = 0, const uint64_t default_value = 0)
     327             : {
     328             :     return cassvalue::uint64ValueOrNull(array,index,default_value);
     329             : }
     330             : 
     331             : inline uint64_t safeUInt64Value(const QByteArray& array, const int index = 0, const uint64_t default_value = 0)
     332             : {
     333             :     return cassvalue::safeUInt64Value(array,index,default_value);
     334             : }
     335             : 
     336             : // Float
     337             : inline void setFloatValue(QByteArray& array, const float value)
     338             : {
     339             :     cassvalue::setFloatValue(array,value);
     340             : }
     341             : 
     342             : inline void appendFloatValue(QByteArray& array, const float value)
     343             : {
     344             :     cassvalue::appendFloatValue(array,value);
     345             : }
     346             : 
     347             : inline float floatValue(const QByteArray& array, const int index = 0)
     348             : {
     349             :     return cassvalue::floatValue(array,index);
     350             : }
     351             : 
     352             : inline float floatValueOrNull(const QByteArray& array, const int index = 0, const float default_value = 0)
     353             : {
     354             :     return cassvalue::floatValueOrNull(array,index,default_value);
     355             : }
     356             : 
     357             : inline float safeFloatValue(const QByteArray& array, const int index = 0, const float default_value = 0)
     358             : {
     359             :     return cassvalue::safeFloatValue(array,index,default_value);
     360             : }
     361             : 
     362             : // Double
     363             : inline void setDoubleValue(QByteArray& array, const double value)
     364             : {
     365             :     cassvalue::setDoubleValue(array,value);
     366             : }
     367             : 
     368             : inline void appendDoubleValue(QByteArray& array, const double value)
     369             : {
     370             :     cassvalue::appendDoubleValue(array,value);
     371             : }
     372             : 
     373             : inline double doubleValue(const QByteArray& array, const int index = 0)
     374             : {
     375             :     return cassvalue::doubleValue(array,index);
     376             : }
     377             : 
     378             : inline double doubleValueOrNull(const QByteArray& array, const int index = 0, const double default_value = 0)
     379             : {
     380             :     return cassvalue::doubleValueOrNull(array,index,default_value);
     381             : }
     382             : 
     383             : inline double safeDoubleValue(const QByteArray& array, const int index = 0, const double default_value = 0.0)
     384             : {
     385             :     return cassvalue::safeDoubleValue(array,index,default_value);
     386             : }
     387             : 
     388             : // String
     389             : inline void setStringValue(QByteArray& array, const QString& value)
     390             : {
     391             :     cassvalue::setStringValue(array,value);
     392             : }
     393             : 
     394           0 : inline void appendStringValue(QByteArray& array, const QString& value)
     395             : {
     396           0 :     cassvalue::appendStringValue(array,value);
     397           0 : }
     398             : 
     399           0 : inline QString stringValue(const QByteArray& array, const int index = 0, int size = -1)
     400             : {
     401           0 :     return cassvalue::stringValue(array,index,size);
     402             : }
     403             : 
     404             : // Binary
     405             : inline void setBinaryValue(QByteArray& array, const QByteArray& value)
     406             : {
     407             :     cassvalue::setBinaryValue(array,value);
     408             : }
     409             : 
     410           0 : inline void appendBinaryValue(QByteArray& array, const QByteArray& value)
     411             : {
     412           0 :     cassvalue::appendBinaryValue(array,value);
     413           0 : }
     414             : 
     415           0 : inline QByteArray binaryValue(const QByteArray& array, const int index = 0, int size = -1)
     416             : {
     417           0 :     return cassvalue::binaryValue(array,index,size);
     418             : }
     419             : 
     420             : 
     421             : 
     422             : 
     423           0 : class QCassandraEncoder : public cassvalue::Encoder
     424             : {
     425             : public:
     426           0 :     QCassandraEncoder(int reserve_size) : cassvalue::Encoder(reserve_size) {}
     427             : };
     428             : 
     429             : 
     430           0 : class QCassandraDecoder : public cassvalue::Decoder
     431             : {
     432             : public:
     433           0 :     QCassandraDecoder(QByteArray const & encoded) : cassvalue::Decoder(encoded) {}
     434             : };
     435             : 
     436             : 
     437             : 
     438             : /*******************************************************************************
     439             :  * value
     440             :  *******************************************************************************/
     441             : 
     442             : 
     443           0 : class value : public cassvalue::Value
     444             : {
     445             : public:
     446             :     static const int32_t    TTL_PERMANENT = 0;
     447             : 
     448             :     // TTL must be positive, although Cassandra allows 0 as "permanent"
     449             :     typedef int32_t         cassandra_ttl_t;
     450             : 
     451             :     enum timestamp_mode_t {
     452             :         TIMESTAMP_MODE_CASSANDRA,
     453             :         TIMESTAMP_MODE_AUTO,
     454             :         TIMESTAMP_MODE_DEFINED
     455             :     };
     456             : 
     457             :     // CASSANDRA_VALUE_TYPE_BINARY (empty buffer)
     458             :     value();
     459             : 
     460             :     // CASSANDRA_VALUE_TYPE_INTEGER
     461             :     value(bool value);
     462             :     value(char value);
     463             :     value(signed char value);
     464             :     value(unsigned char value);
     465             :     value(int16_t value);
     466             :     value(uint16_t value);
     467             :     value(int32_t value);
     468             :     value(uint32_t value);
     469             :     value(int64_t value);
     470             :     value(uint64_t value);
     471             : 
     472             :     // CASSANDRA_VALUE_TYPE_FLOAT
     473             :     value(float value);
     474             :     value(double value);
     475             : 
     476             :     // CASSANDRA_VALUE_TYPE_STRING
     477             :     value(const QString& value);
     478             : 
     479             :     // CASSANDRA_VALUE_TYPE_BINARY
     480             :     value(const QByteArray& value);
     481             :     value(const char *data, int size);
     482             : 
     483             :     bool operator == (const value& rhs);
     484             :     bool operator != (const value& rhs);
     485             : 
     486             :     int32_t ttl() const;
     487             :     void setTtl(int32_t ttl = TTL_PERMANENT);
     488             : 
     489             :     consistency_level_t consistencyLevel() const;
     490             :     void setConsistencyLevel(consistency_level_t level);
     491             : 
     492             : private:
     493             :     cassandra_ttl_t             f_ttl = TTL_PERMANENT;
     494             :     consistency_level_t         f_consistency_level = CONSISTENCY_LEVEL_DEFAULT;
     495             :     timestamp_mode_t            f_timestamp_mode = TIMESTAMP_MODE_AUTO;
     496             :     int64_t                     f_timestamp = 0;
     497             : };
     498             : 
     499             : 
     500             : 
     501             : } // namespace libdbproxy
     502             : // vim: ts=4 sw=4 et

Generated by: LCOV version 1.13