libQtCassandra 0.3.2

QCassandraValue.cpp

Go to the documentation of this file.
00001 /*
00002  * Text:
00003  *      QCassandraValue.cpp
00004  *
00005  * Description:
00006  *      Handling of a cell value.
00007  *
00008  * Documentation:
00009  *      See each function below.
00010  *
00011  * License:
00012  *      Copyright (c) 2011 Made to Order Software Corp.
00013  * 
00014  *      http://snapwebsites.org/
00015  *      contact@m2osw.com
00016  * 
00017  *      Permission is hereby granted, free of charge, to any person obtaining a
00018  *      copy of this software and associated documentation files (the
00019  *      "Software"), to deal in the Software without restriction, including
00020  *      without limitation the rights to use, copy, modify, merge, publish,
00021  *      distribute, sublicense, and/or sell copies of the Software, and to
00022  *      permit persons to whom the Software is furnished to do so, subject to
00023  *      the following conditions:
00024  *
00025  *      The above copyright notice and this permission notice shall be included
00026  *      in all copies or substantial portions of the Software.
00027  *
00028  *      THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00029  *      OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *      MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
00031  *      IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00032  *      CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00033  *      TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00034  *      SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  */
00036 
00037 #include "QtCassandra/QCassandraValue.h"
00038 #include <stdexcept>
00039 
00040 namespace QtCassandra
00041 {
00042 
00212 QCassandraValue::QCassandraValue()
00213     //: f_value() -- auto-init
00214     //  f_ttl(TTL_PERMANENT) -- auto-init
00215     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00216     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00217     //  f_timestamp(0) -- auto-init
00218 {
00219     // an empty f_value() already represents a NULL
00220 }
00221 
00229 QCassandraValue::QCassandraValue(bool value)
00230     //: f_value() -- auto-init
00231     //  f_ttl(TTL_PERMANENT) -- auto-init
00232     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00233     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00234     //  f_timestamp(0) -- auto-init
00235 {
00236     QtCassandra::setBoolValue(f_value, value);
00237 }
00238 
00247 QCassandraValue::QCassandraValue(char value)
00248     //: f_value() -- auto-init
00249     //  f_ttl(TTL_PERMANENT) -- auto-init
00250     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00251     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00252     //  f_timestamp(0) -- auto-init
00253 {
00254     QtCassandra::setCharValue(f_value, value);
00255 }
00256 
00264 QCassandraValue::QCassandraValue(signed char value)
00265     //: f_value() -- auto-init
00266     //  f_ttl(TTL_PERMANENT) -- auto-init
00267     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00268     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00269     //  f_timestamp(0) -- auto-init
00270 {
00271     QtCassandra::setSignedCharValue(f_value, value);
00272 }
00273 
00281 QCassandraValue::QCassandraValue(unsigned char value)
00282     //: f_value() -- auto-init
00283     //  f_ttl(TTL_PERMANENT) -- auto-init
00284     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00285     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00286     //  f_timestamp(0) -- auto-init
00287 {
00288     QtCassandra::setUnsignedCharValue(f_value, value);
00289 }
00290 
00298 QCassandraValue::QCassandraValue(int16_t value)
00299     //: f_value() -- auto-init
00300     //  f_ttl(TTL_PERMANENT) -- auto-init
00301     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00302     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00303     //  f_timestamp(0) -- auto-init
00304 {
00305     QtCassandra::setInt16Value(f_value, value);
00306 }
00307 
00315 QCassandraValue::QCassandraValue(uint16_t value)
00316     //: f_value() -- auto-init
00317     //  f_ttl(TTL_PERMANENT) -- auto-init
00318     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00319     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00320     //  f_timestamp(0) -- auto-init
00321 {
00322     QtCassandra::setUInt16Value(f_value, value);
00323 }
00324 
00332 QCassandraValue::QCassandraValue(int32_t value)
00333     //: f_value() -- auto-init
00334     //  f_ttl(TTL_PERMANENT) -- auto-init
00335     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00336     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00337     //  f_timestamp(0) -- auto-init
00338 {
00339     QtCassandra::setInt32Value(f_value, value);
00340 }
00341 
00349 QCassandraValue::QCassandraValue(uint32_t value)
00350     //: f_value() -- auto-init
00351     //  f_ttl(TTL_PERMANENT) -- auto-init
00352     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00353     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00354     //  f_timestamp(0) -- auto-init
00355 {
00356     QtCassandra::setUInt32Value(f_value, value);
00357 }
00358 
00366 QCassandraValue::QCassandraValue(int64_t value)
00367     //: f_value() -- auto-init
00368     //  f_ttl(TTL_PERMANENT) -- auto-init
00369     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00370     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00371     //  f_timestamp(0) -- auto-init
00372 {
00373     QtCassandra::setInt64Value(f_value, value);
00374 }
00375 
00383 QCassandraValue::QCassandraValue(uint64_t value)
00384     //: f_value() -- auto-init
00385     //  f_ttl(TTL_PERMANENT) -- auto-init
00386     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00387     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00388     //  f_timestamp(0) -- auto-init
00389 {
00390     QtCassandra::setUInt64Value(f_value, value);
00391 }
00392 
00400 QCassandraValue::QCassandraValue(float value)
00401     //: f_value() -- auto-init
00402     //  f_ttl(TTL_PERMANENT) -- auto-init
00403     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00404     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00405     //  f_timestamp(0) -- auto-init
00406 {
00407     QtCassandra::setFloatValue(f_value, value);
00408 }
00409 
00417 QCassandraValue::QCassandraValue(double value)
00418     //: f_value() -- auto-init
00419     //  f_ttl(TTL_PERMANENT) -- auto-init
00420     //  f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00421     //  f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00422     //  f_timestamp(0) -- auto-init
00423 {
00424     QtCassandra::setDoubleValue(f_value, value);
00425 }
00426 
00434 QCassandraValue::QCassandraValue(const QString& value)
00435     : f_value(value.toUtf8())
00436       //f_ttl(TTL_PERMANENT) -- auto-init
00437       //f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00438       //f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00439       //f_timestamp(0) -- auto-init
00440 {
00441     // f_value properly initialized already
00442 }
00443 
00450 QCassandraValue::QCassandraValue(const QByteArray& value)
00451     : f_value(value)
00452       //f_ttl(TTL_PERMANENT) -- auto-init
00453       //f_consistency_level(CONSISTENCY_LEVEL_DEFAULT) -- auto-init
00454       //f_timestamp_mode(TIMESTAMP_MODE_AUTO) -- auto-init
00455       //f_timestamp(0) -- auto-init
00456 {
00457     // f_value properly initialized already
00458 }
00459 
00464 void QCassandraValue::setNullValue()
00465 {
00466     QtCassandra::setNullValue(f_value);
00467 }
00468 
00478 void QCassandraValue::setBoolValue(bool value)
00479 {
00480     QtCassandra::setBoolValue(f_value, value);
00481 }
00482 
00492 void QCassandraValue::setCharValue(char value)
00493 {
00494     QtCassandra::setCharValue(f_value, value);
00495 }
00496 
00506 void QCassandraValue::setSignedCharValue(signed char value)
00507 {
00508     QtCassandra::setSignedCharValue(f_value, value);
00509 }
00510 
00520 void QCassandraValue::setUnsignedCharValue(unsigned char value)
00521 {
00522     QtCassandra::setUnsignedCharValue(f_value, value);
00523 }
00524 
00534 void QCassandraValue::setInt16Value(int16_t value)
00535 {
00536     QtCassandra::setInt16Value(f_value, value);
00537 }
00538 
00548 void QCassandraValue::setUInt16Value(uint16_t value)
00549 {
00550     QtCassandra::setUInt16Value(f_value, value);
00551 }
00552 
00560 void QCassandraValue::setInt32Value(int32_t value)
00561 {
00562     QtCassandra::setInt32Value(f_value, value);
00563 }
00564 
00574 void QCassandraValue::setUInt32Value(uint32_t value)
00575 {
00576     QtCassandra::setUInt32Value(f_value, value);
00577 }
00578 
00586 void QCassandraValue::setInt64Value(int64_t value)
00587 {
00588     QtCassandra::setInt64Value(f_value, value);
00589 }
00590 
00598 void QCassandraValue::setUInt64Value(uint64_t value)
00599 {
00600     QtCassandra::setUInt64Value(f_value, value);
00601 }
00602 
00610 void QCassandraValue::setFloatValue(float value)
00611 {
00612     QtCassandra::setFloatValue(f_value, value);
00613 }
00614 
00622 void QCassandraValue::setDoubleValue(double value)
00623 {
00624     QtCassandra::setDoubleValue(f_value, value);
00625 }
00626 
00640 void QCassandraValue::setStringValue(const QString& value)
00641 {
00642     if(value.size() > 64 * 1024 * 1024) {
00643         throw std::runtime_error("string value is more than 64Mb");
00644     }
00645     QtCassandra::setStringValue(f_value, value);
00646 }
00647 
00662 void QCassandraValue::setBinaryValue(const QByteArray& value)
00663 {
00664     if(value.size() > 64 * 1024 * 1024) {
00665         throw std::runtime_error("binary value is more than 64Mb");
00666     }
00667     QtCassandra::setBinaryValue(f_value, value);
00668 }
00669 
00678 int QCassandraValue::size() const
00679 {
00680     return f_value.size();
00681 }
00682 
00689 bool QCassandraValue::nullValue() const
00690 {
00691     return f_value.size() == 0;
00692 }
00693 
00707 char QCassandraValue::charValue() const
00708 {
00709     if(f_value.size() < 1) {
00710         throw std::runtime_error("buffer too small for this value");
00711     }
00712     return f_value.at(0);
00713 }
00714 
00727 signed char QCassandraValue::signedCharValue() const
00728 {
00729     if(f_value.size() < 1) {
00730         throw std::runtime_error("buffer too small for this value");
00731     }
00732     return static_cast<signed char>(f_value.at(0));
00733 }
00734 
00748 unsigned char QCassandraValue::unsignedCharValue() const
00749 {
00750     if(f_value.size() < 1) {
00751         throw std::runtime_error("buffer too small for this value");
00752     }
00753     return static_cast<unsigned char>(f_value.at(0));
00754 }
00755 
00769 int16_t QCassandraValue::int16Value() const
00770 {
00771     if(f_value.size() < 2) {
00772         throw std::runtime_error("buffer too small for this value");
00773     }
00774     return (static_cast<int16_t>(static_cast<unsigned char>(f_value.at(0))) << 8)
00775          | static_cast<int16_t>(static_cast<unsigned char>(f_value.at(1)));
00776 }
00777 
00791 uint16_t QCassandraValue::uint16Value() const
00792 {
00793     if(f_value.size() < 2) {
00794         throw std::runtime_error("buffer too small for this value");
00795     }
00796     return (static_cast<uint16_t>(static_cast<unsigned char>(f_value.at(0))) << 8)
00797          | static_cast<uint16_t>(static_cast<unsigned char>(f_value.at(1)));
00798 }
00799 
00813 int32_t QCassandraValue::int32Value() const
00814 {
00815     if(f_value.size() < 4) {
00816         throw std::runtime_error("buffer too small for this value");
00817     }
00818     return (static_cast<int32_t>(static_cast<unsigned char>(f_value.at(0))) << 24)
00819          | (static_cast<int32_t>(static_cast<unsigned char>(f_value.at(1))) << 16)
00820          | (static_cast<int32_t>(static_cast<unsigned char>(f_value.at(2))) << 8)
00821          | static_cast<int32_t>(static_cast<unsigned char>(f_value.at(3)));
00822 }
00823 
00837 uint32_t QCassandraValue::uint32Value() const
00838 {
00839     if(f_value.size() < 4) {
00840         throw std::runtime_error("buffer too small for this value");
00841     }
00842     return (static_cast<uint32_t>(static_cast<unsigned char>(f_value.at(0))) << 24)
00843          | (static_cast<uint32_t>(static_cast<unsigned char>(f_value.at(1))) << 16)
00844          | (static_cast<uint32_t>(static_cast<unsigned char>(f_value.at(2))) << 8)
00845          | static_cast<uint32_t>(static_cast<unsigned char>(f_value.at(3)));
00846 }
00847 
00861 int64_t QCassandraValue::int64Value() const
00862 {
00863     if(f_value.size() < 8) {
00864         throw std::runtime_error("buffer too small for this value");
00865     }
00866     return (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(0))) << 56)
00867          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(1))) << 48)
00868          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(2))) << 40)
00869          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(3))) << 32)
00870          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(4))) << 24)
00871          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(5))) << 16)
00872          | (static_cast<int64_t>(static_cast<unsigned char>(f_value.at(6))) << 8)
00873          | static_cast<int64_t>(static_cast<unsigned char>(f_value.at(7)));
00874 }
00875 
00889 uint64_t QCassandraValue::uint64Value() const
00890 {
00891     if(f_value.size() < 8) {
00892         throw std::runtime_error("buffer too small for this value");
00893     }
00894     return (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(0))) << 56)
00895          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(1))) << 48)
00896          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(2))) << 40)
00897          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(3))) << 32)
00898          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(4))) << 24)
00899          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(5))) << 16)
00900          | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(6))) << 8)
00901          | static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(7)));
00902 }
00903 
00917 float QCassandraValue::floatValue() const
00918 {
00919     if(f_value.size() < 4) {
00920         throw std::runtime_error("buffer too small for this value");
00921     }
00922     union switch_t {
00923         uint32_t    v;
00924         float       f;
00925     };
00926     switch_t s;
00927     s.v = static_cast<uint32_t>((static_cast<unsigned char>(f_value.at(0))) << 24)
00928         | static_cast<uint32_t>((static_cast<unsigned char>(f_value.at(1))) << 16)
00929         | static_cast<uint32_t>((static_cast<unsigned char>(f_value.at(2))) << 8)
00930         | static_cast<uint32_t>(static_cast<unsigned char>(f_value.at(3)));
00931     return s.f;
00932 }
00933 
00947 double QCassandraValue::doubleValue() const
00948 {
00949     if(f_value.size() < 8) {
00950         throw std::runtime_error("buffer too small for this value");
00951     }
00952     union switch_t {
00953         uint64_t    v;
00954         float       f;
00955     };
00956     switch_t s;
00957     s.v = (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(0))) << 56)
00958         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(1))) << 48)
00959         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(2))) << 40)
00960         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(3))) << 32)
00961         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(4))) << 24)
00962         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(5))) << 16)
00963         | (static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(6))) << 8)
00964         | static_cast<uint64_t>(static_cast<unsigned char>(f_value.at(7)));
00965     return s.f;
00966 }
00967 
00974 QString QCassandraValue::stringValue() const
00975 {
00976     return QString::fromUtf8(f_value.data(), f_value.size());
00977 }
00978 
00989 const QByteArray& QCassandraValue::binaryValue() const
00990 {
00991     return f_value;
00992 }
00993 
01003 QCassandraValue& QCassandraValue::operator = (const char * /*null_value*/)
01004 {
01005     QtCassandra::setNullValue(f_value);
01006     return *this;
01007 }
01008 
01018 QCassandraValue& QCassandraValue::operator = (bool value)
01019 {
01020     QtCassandra::setBoolValue(f_value, value);
01021     return *this;
01022 }
01023 
01033 QCassandraValue& QCassandraValue::operator = (char value)
01034 {
01035     QtCassandra::setCharValue(f_value, value);
01036     return *this;
01037 }
01038 
01048 QCassandraValue& QCassandraValue::operator = (signed char value)
01049 {
01050     QtCassandra::setSignedCharValue(f_value, value);
01051     return *this;
01052 }
01053 
01063 QCassandraValue& QCassandraValue::operator = (unsigned char value)
01064 {
01065     QtCassandra::setUnsignedCharValue(f_value, value);
01066     return *this;
01067 }
01068 
01078 QCassandraValue& QCassandraValue::operator = (int16_t value)
01079 {
01080     QtCassandra::setInt16Value(f_value, value);
01081     return *this;
01082 }
01083 
01093 QCassandraValue& QCassandraValue::operator = (uint16_t value)
01094 {
01095     QtCassandra::setUInt16Value(f_value, value);
01096     return *this;
01097 }
01098 
01108 QCassandraValue& QCassandraValue::operator = (int32_t value)
01109 {
01110     QtCassandra::setInt32Value(f_value, value);
01111     return *this;
01112 }
01113 
01123 QCassandraValue& QCassandraValue::operator = (uint32_t value)
01124 {
01125     QtCassandra::setUInt32Value(f_value, value);
01126     return *this;
01127 }
01128 
01138 QCassandraValue& QCassandraValue::operator = (int64_t value)
01139 {
01140     QtCassandra::setInt64Value(f_value, value);
01141     return *this;
01142 }
01143 
01153 QCassandraValue& QCassandraValue::operator = (uint64_t value)
01154 {
01155     QtCassandra::setUInt64Value(f_value, value);
01156     return *this;
01157 }
01158 
01168 QCassandraValue& QCassandraValue::operator = (float value)
01169 {
01170     QtCassandra::setFloatValue(f_value, value);
01171     return *this;
01172 }
01173 
01183 QCassandraValue& QCassandraValue::operator = (double value)
01184 {
01185     QtCassandra::setDoubleValue(f_value, value);
01186     return *this;
01187 }
01188 
01198 QCassandraValue& QCassandraValue::operator = (const QString& value)
01199 {
01200     if(value.size() > 64 * 1024 * 1024) {
01201         throw std::runtime_error("string value is more than 64Mb");
01202     }
01203     QtCassandra::setStringValue(f_value, value);
01204     return *this;
01205 }
01206 
01215 QCassandraValue& QCassandraValue::operator = (const QByteArray& value)
01216 {
01217     if(value.size() > 64 * 1024 * 1024) {
01218         throw std::runtime_error("binary value is more than 64Mb");
01219     }
01220     QtCassandra::setBinaryValue(f_value, value);
01221     return *this;
01222 }
01223 
01236 bool QCassandraValue::operator == (const QCassandraValue& rhs)
01237 {
01238     if(f_value.size() != rhs.size()) {
01239         return false;
01240     }
01241     if(f_ttl != rhs.f_ttl) {
01242         return false;
01243     }
01244     if(f_consistency_level != rhs.f_consistency_level) {
01245         return false;
01246     }
01247     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) == 0;
01248 }
01249 
01263 bool QCassandraValue::operator != (const QCassandraValue& rhs)
01264 {
01265     if(f_value.size() != rhs.size()) {
01266         return true;
01267     }
01268     if(f_ttl != rhs.f_ttl) {
01269         return true;
01270     }
01271     if(f_consistency_level != rhs.f_consistency_level) {
01272         return true;
01273     }
01274     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) != 0;
01275 }
01276 
01290 bool QCassandraValue::operator < (const QCassandraValue& rhs)
01291 {
01292     if(f_value.size() < rhs.size()) {
01293         return true;
01294     }
01295     if(f_value.size() > rhs.size()) {
01296         return false;
01297     }
01298     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) < 0;
01299 }
01300 
01314 bool QCassandraValue::operator <= (const QCassandraValue& rhs)
01315 {
01316     if(f_value.size() < rhs.size()) {
01317         return true;
01318     }
01319     if(f_value.size() > rhs.size()) {
01320         return false;
01321     }
01322     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) <= 0;
01323 }
01324 
01338 bool QCassandraValue::operator > (const QCassandraValue& rhs)
01339 {
01340     if(f_value.size() < rhs.size()) {
01341         return false;
01342     }
01343     if(f_value.size() > rhs.size()) {
01344         return true;
01345     }
01346     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) > 0;
01347 }
01348 
01362 bool QCassandraValue::operator >= (const QCassandraValue& rhs)
01363 {
01364     if(f_value.size() < rhs.size()) {
01365         return false;
01366     }
01367     if(f_value.size() > rhs.size()) {
01368         return true;
01369     }
01370     return memcmp(f_value.data(), rhs.f_value.data(), f_value.size()) >= 0;
01371 }
01372 
01384 int32_t QCassandraValue::ttl() const
01385 {
01386     return f_ttl;
01387 }
01388 
01405 void QCassandraValue::setTtl(int32_t ttl)
01406 {
01407     if(ttl < 0) {
01408         throw std::runtime_error("the TTL value cannot be negative");
01409     }
01410 
01411     f_ttl = ttl;
01412 }
01413 
01425 consistency_level_t QCassandraValue::consistencyLevel() const
01426 {
01427     return f_consistency_level;
01428 }
01429 
01455 void QCassandraValue::setConsistencyLevel(consistency_level_t level)
01456 {
01457     // we cannot use a switch because these are not really
01458     // constants (i.e. these are pointers to values); although
01459     // we could cast to the Cassandra definition and switch on
01460     // those...
01461     if(level != CONSISTENCY_LEVEL_DEFAULT
01462     && level != CONSISTENCY_LEVEL_ONE
01463     && level != CONSISTENCY_LEVEL_QUORUM
01464     && level != CONSISTENCY_LEVEL_LOCAL_QUORUM
01465     && level != CONSISTENCY_LEVEL_EACH_QUORUM
01466     && level != CONSISTENCY_LEVEL_ALL
01467     && level != CONSISTENCY_LEVEL_ANY
01468     && level != CONSISTENCY_LEVEL_TWO
01469     && level != CONSISTENCY_LEVEL_THREE) {
01470         throw std::runtime_error("invalid consistency level");
01471     }
01472 
01473     f_consistency_level = level;
01474 }
01475 
01490 QCassandraValue::timestamp_mode_t QCassandraValue::timestampMode() const
01491 {
01492     return f_timestamp_mode;
01493 }
01494 
01510 void QCassandraValue::setTimestampMode(timestamp_mode_t mode)
01511 {
01512     switch(mode) {
01513     case TIMESTAMP_MODE_CASSANDRA:
01514     case TIMESTAMP_MODE_AUTO:
01515         break;
01516 
01517     default:
01518         throw std::runtime_error("invalid timestamp mode in setTimestampMode()");
01519 
01520     }
01521     f_timestamp_mode = mode;
01522 }
01523 
01540 int64_t QCassandraValue::timestamp() const
01541 {
01542     return f_timestamp;
01543 }
01544 
01584 void QCassandraValue::setTimestamp(int64_t timestamp)
01585 {
01586     f_timestamp_mode = TIMESTAMP_MODE_DEFINED;
01587     f_timestamp = timestamp;
01588 }
01589 
01598 void QCassandraValue::assignTimestamp(int64_t timestamp)
01599 {
01600     f_timestamp = timestamp;
01601 }
01602 
01603 } // namespace QtCassandra
01604 // vim: ts=4 sw=4 et
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

This document is part of the libQtCassandra Project.

Copyright by Made to Order Software Corp.