Commit b4d29ae6 authored by Michael Ott's avatar Michael Ott
Browse files

Make return value of serialize() const and overloard < operator

parent 40d92b70
//================================================================================
// Name : sensorid.h
// Author : Axel Auweter
// Copyright : Leibniz Supercomputing Centre
// Description : C++ API for handling DCDB SensorIDs
//================================================================================
//================================================================================
// This file is part of DCDB (DataCenter DataBase)
// Copyright (C) 2011-2016 Leibniz Supercomputing Centre
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//================================================================================
/*
* sensorid.h
*
* Created on: May 18, 2015
* Author: Axel Auweter
*/
#include <cstdint>
#include <string>
......@@ -121,7 +102,7 @@ public:
* corresponds to the supplied SensorId object.
* @return Returns the serialized string that can be used by Cassandra as row key.
*/
std::string serialize();
std::string serialize() const;
/**
* @brief This function matches the sensor against a
......@@ -136,6 +117,13 @@ public:
(data.raw[1] == rhs.data.raw[1]);}
#endif
inline bool operator < (const SensorId& rhs) const {
if (data.raw[0] == rhs.data.raw[0])
return data.raw[1] < rhs.data.raw[1];
else
return data.raw[0] < rhs.data.raw[0];
}
SensorId();
SensorId(std::string mqttTopic);
virtual ~SensorId();
......
......@@ -134,7 +134,7 @@ void SensorDataStoreImpl::insert(SensorId* sid, uint64_t ts, int64_t value)
sid->setRsvd(week);
/* Insert into Cassandra */
std::string key = sid->serialize();
const std::string key = sid->serialize();
CassError rc = CASS_OK;
CassStatement* statement = NULL;
......@@ -195,7 +195,7 @@ void SensorDataStoreImpl::query(std::list<SensorDataStoreReading>& result, Senso
prepared = cass_future_get_prepared(future);
cass_future_free(future);
std::string key = sid.serialize();
const std::string key = sid.serialize();
#if 0
std::cout << "Query: " << query << std::endl << "sid: " << key << " ts1: " << start.getRaw() << " ts2: " << end.getRaw() << std::endl;
......@@ -274,7 +274,7 @@ void SensorDataStoreImpl::queryCB(SensorDataStore::QueryCbFunc cbFunc, void* use
prepared = cass_future_get_prepared(future);
cass_future_free(future);
std::string key = sid.serialize();
const std::string key = sid.serialize();
statement = cass_prepared_bind(prepared);
cass_statement_bind_bytes(statement, 0, (const cass_byte_t*)(key.c_str()), 16);
......@@ -445,7 +445,7 @@ void SensorDataStoreImpl::deleteRow(SensorId& sid)
prepared = cass_future_get_prepared(future);
cass_future_free(future);
std::string key = sid.serialize();
const std::string key = sid.serialize();
statement = cass_prepared_bind(prepared);
cass_statement_bind_bytes(statement, 0, (const cass_byte_t*)(key.c_str()), 16);
......
......@@ -142,7 +142,7 @@ bool SensorId::mqttTopicConvert(std::string mqttTopic)
* big-endian 128-bit character array represented as
* std::string.
*/
std::string SensorId::serialize()
std::string SensorId::serialize() const
{
uint64_t ll[2];
ll[0] = Endian::hostToBE(data.raw[0]);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment