Skip to content

Commit

Permalink
Merged branch 'const-correctness'.
Browse files Browse the repository at this point in the history
  • Loading branch information
artob committed Jun 14, 2016
2 parents 36128a7 + 274d645 commit 42a5b07
Show file tree
Hide file tree
Showing 23 changed files with 131 additions and 166 deletions.
18 changes: 10 additions & 8 deletions hdt-lib/include/ControlInformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,45 +83,47 @@ class ControlInformation {

size_t load(const unsigned char *ptr, const unsigned char *maxPtr);

std::string getFormat();
const std::string& getFormat() const;

void setFormat(std::string format);
void setFormat(const std::string& format);

/** Get a property of the ControlInformation
* @param key
* @return
* @throws std::out_of_range if the key is not found
*/
std::string get(std::string key);
const std::string& get(const std::string& key) const;

/** Get a property of the ControlInformation as unsigned int
* @param key
* @return
* @throws std::out_of_range if the key is not found
*/
uint64_t getUint(std::string key);
uint64_t getUint(const std::string& key) const;

/**
* Set a property of the ControlInformation
* @param key
* @param value
*/
void set(std::string key, std::string value);
void set(const std::string& key, const std::string& value);

/**
* Set a property of the ControlInformation as unsigned int
* @param key
* @param value
*/
void setUint(std::string key, uint64_t value);
void setUint(const std::string& key, uint64_t value);

/** Clear the ControlInformation, removing all properties.
*/
void clear();

void setType(ControlInformationType type);

bool isDefined(std::string key);
bool isDefined(const std::string& key) const;

ControlInformationType getType();
ControlInformationType getType() const;
};

}
Expand Down
4 changes: 2 additions & 2 deletions hdt-lib/include/HDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class HDT : public RDFAccess
return search(pattern.getSubject().c_str(), pattern.getPredicate().c_str(), pattern.getObject().c_str());
}

virtual bool isIndexed()=0;
virtual bool isIndexed() const = 0;
};

/**
Expand Down Expand Up @@ -146,6 +146,6 @@ class ModifiableHDT : public HDT {

};

}
} // namespace hdt

#endif /* HDT_HDT_HPP_ */
14 changes: 9 additions & 5 deletions hdt-lib/include/HDTSpecification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,20 @@ class HDTSpecification
* @param filename
* @return
*/
HDTSpecification(std::string &filename);
HDTSpecification(const std::string& filename);

/** Add a set of options using the syntax property1:value1;property2:value2 */
void setOptions(std::string options);
void setOptions(const std::string& options);

/** Get the value of a property */
std::string get(std::string key);
/**
* Get the value of a property.
*
* @throws std::out_of_range if the key is not found
*/
const std::string& get(const std::string& key);

/** Set the value of a property */
void set(std::string key, std::string value);
void set(const std::string& key, const std::string& value);
};

}
Expand Down
19 changes: 9 additions & 10 deletions hdt-lib/include/Triples.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ class ModifiableTriples;
class Triples {
public:

virtual ~Triples() {
}
virtual ~Triples() {}

/**
* Allows to search a pattern of triples.
Expand All @@ -77,19 +76,19 @@ class Triples {
* @param triple
* @return
*/
virtual float cost(TripleID &triple)=0;
virtual float cost(TripleID &triple) const = 0;

/**
* Returns the number of triples
*
* @return
*/
virtual size_t getNumberOfElements()=0;
virtual size_t getNumberOfElements() const = 0;

/**
* Returns size in bytes of the overall structure.
*/
virtual size_t size()=0;
virtual size_t size() const = 0;

/**
* Serialize the triples to a stream in implementation-specific format.
Expand Down Expand Up @@ -123,9 +122,9 @@ class Triples {

virtual size_t loadIndex(unsigned char *ptr, unsigned char *ptrMax, ProgressListener *listener=NULL)=0;

virtual bool isIndexed()=0;
virtual bool isIndexed() const = 0;

virtual size_t getNumAppearances(size_t /*pred*/) {
virtual size_t getNumAppearances(size_t /*pred*/) const {
return 0;
}

Expand All @@ -137,9 +136,9 @@ class Triples {
*/
virtual void populateHeader(Header &header, string rootNode)=0;

virtual string getType()=0;
virtual string getType() const = 0;

virtual TripleComponentOrder getOrder()=0;
virtual TripleComponentOrder getOrder() const = 0;
}; // Triples{}

/**
Expand Down Expand Up @@ -201,6 +200,6 @@ class ModifiableTriples: public Triples {
virtual void stopProcessing(ProgressListener *listener = NULL)=0;
};

}
} // namespace hdt

#endif /* HDT_TRIPLES_HPP_ */
2 changes: 1 addition & 1 deletion hdt-lib/src/hdt/BasicHDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class BasicHDT : public HDT {
*/
IteratorTripleString *search(const char *subject, const char *predicate, const char *object);

bool isIndexed() {
bool isIndexed() const {
return triples->isIndexed();
}
};
Expand Down
2 changes: 1 addition & 1 deletion hdt-lib/src/hdt/BasicModifiableHDT.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class BasicModifiableHDT : public ModifiableHDT {

void remove(IteratorTripleString *triples);

bool isIndexed() {
bool isIndexed() const {
return false;
}
};
Expand Down
43 changes: 18 additions & 25 deletions hdt-lib/src/hdt/ControlInformation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,23 @@
#include "ControlInformation.hpp"
#include "../util/crc16.h"


using namespace std;

namespace hdt {

ControlInformation::ControlInformation() : type(UNKNOWN_CI) {

}

ControlInformation::~ControlInformation() {
ControlInformation::ControlInformation() : type(UNKNOWN_CI) {}

}
ControlInformation::~ControlInformation() {}

void ControlInformation::save(std::ostream &out) {
CRC16 crc;
unsigned char null='\0';
const unsigned char null='\0';

// Write cookie
crc.writeData(out, (unsigned char*)"$HDT", 4);

// Write type
uint8_t typeValue = (uint8_t) type;
const uint8_t typeValue = (uint8_t) type;
crc.writeData(out, (unsigned char *)&typeValue, sizeof(uint8_t));

// Write format
Expand All @@ -79,7 +74,7 @@ void ControlInformation::save(std::ostream &out) {

void ControlInformation::load(std::istream &in) {
CRC16 crc;
unsigned char null='\0';
const unsigned char null='\0';

this->clear();

Expand Down Expand Up @@ -119,7 +114,7 @@ void ControlInformation::load(std::istream &in) {
crc.update((unsigned char *)line.c_str(), line.length());
crc.update(&null, 1);

crc16_t filecrc = crc16_read(in);
const crc16_t filecrc = crc16_read(in);

// CRC16
if(filecrc!=crc.getValue()) {
Expand Down Expand Up @@ -181,7 +176,7 @@ size_t ControlInformation::load(const unsigned char *ptr, const unsigned char *m
CRC16 crc;
crc.update(&ptr[0], count);
CHECKPTR(ptr,maxPtr, sizeof(crc16_t));
crc16_t filecrc = *((crc16_t *)&ptr[count]);
const crc16_t filecrc = *((crc16_t *)&ptr[count]);
if(filecrc!=crc.getValue()) {
throw "CRC of control information does not match.";
}
Expand All @@ -197,28 +192,27 @@ void ControlInformation::clear() {
}


std::string ControlInformation::getFormat() {
const std::string& ControlInformation::getFormat() const {
return format;
}

void ControlInformation::setFormat(std::string format) {
void ControlInformation::setFormat(const std::string& format) {
this->format = format;
}

std::string ControlInformation::get(std::string key) {
return map[key];
const std::string& ControlInformation::get(const std::string& key) const {
return map.at(key);
}

void ControlInformation::set(std::string key, std::string value) {
void ControlInformation::set(const std::string& key, const std::string& value) {
map[key] = value;
}

uint64_t ControlInformation::getUint(std::string key) {
std::string str = map[key];
return strtoull(str.c_str(), NULL, 10);
uint64_t ControlInformation::getUint(const std::string& key) const {
return strtoull(map.at(key).c_str(), NULL, 10);
}

void ControlInformation::setUint(std::string key, uint64_t value) {
void ControlInformation::setUint(const std::string& key, uint64_t value) {
std::stringstream out;
out << value;
map[key] = out.str();
Expand All @@ -228,12 +222,11 @@ void ControlInformation::setType(ControlInformationType type) {
this->type = type;
}


bool ControlInformation::isDefined(std::string key) {
return !map[key].empty();
bool ControlInformation::isDefined(const std::string& key) const {
return map.count(key) && !(map.at(key).empty());
}

ControlInformationType ControlInformation::getType() {
ControlInformationType ControlInformation::getType() const {
return this->type;
}

Expand Down
20 changes: 8 additions & 12 deletions hdt-lib/src/hdt/HDTSpecification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,10 @@

namespace hdt {

HDTSpecification::HDTSpecification() {}

HDTSpecification::HDTSpecification() {

}

HDTSpecification::HDTSpecification(std::string &filename) {
if(filename!=""){
HDTSpecification::HDTSpecification(const std::string& filename) {
if(!filename.empty()){
try {
PropertyUtil::read(filename.c_str(), map);
} catch (char *except) {
Expand All @@ -47,7 +44,7 @@ HDTSpecification::HDTSpecification(std::string &filename) {
}
}

void HDTSpecification::setOptions(std::string options) {
void HDTSpecification::setOptions(const std::string& options) {
std::istringstream strm(options);
std::string singleOption;
while(getline(strm, singleOption, ';') ){
Expand All @@ -62,13 +59,12 @@ void HDTSpecification::setOptions(std::string options) {
}
}

std::string HDTSpecification::get(std::string key) {
return map[key];
const std::string& HDTSpecification::get(const std::string& key) {
return map.at(key);
}

void HDTSpecification::set(std::string key, std::string value) {
void HDTSpecification::set(const std::string& key, const std::string& value) {
map[key] = value;
}


}
} // namespace hdt
14 changes: 7 additions & 7 deletions hdt-lib/src/triples/BitmapTriples.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ BitmapTriples::~BitmapTriples() {
delete arrayZ;
}

float BitmapTriples::cost(TripleID & triple)
float BitmapTriples::cost(TripleID & triple) const
{
CHECK_BITMAPTRIPLES_INITIALIZED
return 0;
Expand Down Expand Up @@ -576,11 +576,12 @@ void BitmapTriples::populateHeader(Header &header, string rootNode) {
#endif
}

string BitmapTriples::getType() {
string BitmapTriples::getType() const
{
return HDTVocabulary::TRIPLES_TYPE_BITMAP;
}

TripleComponentOrder BitmapTriples::getOrder()
TripleComponentOrder BitmapTriples::getOrder() const
{
return order;
}
Expand Down Expand Up @@ -882,12 +883,12 @@ size_t BitmapTriples::loadIndex(unsigned char *ptr, unsigned char *ptrMax, Progr
return count;
}

size_t BitmapTriples::getNumberOfElements()
size_t BitmapTriples::getNumberOfElements() const
{
return arrayZ->getNumberOfElements();
}

size_t BitmapTriples::size()
size_t BitmapTriples::size() const
{
if(bitmapY!=NULL && bitmapZ!=NULL) {
return bitmapY->getSizeBytes()
Expand All @@ -900,5 +901,4 @@ size_t BitmapTriples::size()
return arrayY->size()+arrayZ->size()+bitmapY->getSizeBytes()+bitmapZ->getSizeBytes();
}


}
} // namespace hdt

0 comments on commit 42a5b07

Please sign in to comment.