Const correctness enforcement

This commit is contained in:
2018-01-31 14:18:33 +01:00
parent 6d5e8a412b
commit 8642d5b695
8 changed files with 55 additions and 55 deletions
+16 -16
View File
@@ -7,7 +7,7 @@
using namespace std;
hsize_t H5Format::expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step)
hsize_t H5Format::expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step)
{
hsize_t dataset_rank = 3;
hsize_t dataset_dimension[dataset_rank];
@@ -28,7 +28,7 @@ hsize_t H5Format::expand_dataset(const H5::DataSet& dataset, hsize_t frame_index
return dataset_dimension[0];
}
void H5Format::compact_dataset(const H5::DataSet& dataset, hsize_t max_frame_index)
void H5Format::compact_dataset(H5::DataSet& dataset, hsize_t max_frame_index)
{
hsize_t dataset_rank = 3;
hsize_t dataset_dimension[dataset_rank];
@@ -47,12 +47,12 @@ void H5Format::compact_dataset(const H5::DataSet& dataset, hsize_t max_frame_ind
dataset.extend(dataset_dimension);
}
H5::Group H5Format::create_group(H5::Group& target, std::string name)
H5::Group H5Format::create_group(H5::Group& target, const string& name)
{
return target.createGroup(name.c_str());
}
boost::any H5Format::get_value_from_reference(string& dataset_name, boost::any value_reference, map<string, boost::any>& values)
const boost::any& H5Format::get_value_from_reference(const string& dataset_name, const boost::any& value_reference, const map<string, boost::any>& values)
{
try {
auto reference_string = boost::any_cast<string>(value_reference);
@@ -72,7 +72,7 @@ boost::any H5Format::get_value_from_reference(string& dataset_name, boost::any v
}
}
H5::PredType H5Format::get_dataset_data_type(string& type){
H5::PredType H5Format::get_dataset_data_type(const string& type){
#ifdef DEBUG_OUTPUT
cout << "[H5Format::get_dataset_data_type] Getting dataset type for received frame type " << type << endl;
@@ -105,7 +105,7 @@ H5::PredType H5Format::get_dataset_data_type(string& type){
}
}
H5::DataSet H5Format::write_dataset(H5::Group& target, h5_dataset& dataset, map<string, boost::any>& values){
H5::DataSet H5Format::write_dataset(H5::Group& target, const h5_dataset& dataset, const map<string, boost::any>& values){
string name = dataset.name;
boost::any value;
@@ -162,7 +162,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, h5_dataset& dataset, map<
}
}
H5::DataSet H5Format::write_dataset(H5::Group& target, string name, double value)
H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, double value)
{
H5::DataSpace att_space(H5S_SCALAR);
auto data_type = H5::PredType::NATIVE_DOUBLE;
@@ -173,7 +173,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, string name, double value
return dataset;
}
H5::DataSet H5Format::write_dataset(H5::Group& target, string name, int value)
H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, int value)
{
H5::DataSpace att_space(H5S_SCALAR);
auto data_type = H5::PredType::NATIVE_INT;
@@ -184,7 +184,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, string name, int value)
return dataset;
}
H5::DataSet H5Format::write_dataset(H5::Group& target, string name, string value)
H5::DataSet H5Format::write_dataset(H5::Group& target, const string& name, const string& value)
{
H5::DataSpace att_space(H5S_SCALAR);
H5::DataType data_type = H5::StrType(0, H5T_VARIABLE);
@@ -195,7 +195,7 @@ H5::DataSet H5Format::write_dataset(H5::Group& target, string name, string value
return dataset;
}
void H5Format::write_attribute(H5::H5Object& target, string name, string value)
void H5Format::write_attribute(H5::H5Object& target, const string& name, const string& value)
{
H5::DataSpace att_space(H5S_SCALAR);
H5::DataType data_type = H5::StrType(H5::PredType::C_S1, H5T_VARIABLE);
@@ -204,7 +204,7 @@ void H5Format::write_attribute(H5::H5Object& target, string name, string value)
h5_attribute.write(data_type, &value);
}
void H5Format::write_attribute(H5::H5Object& target, string name, int value)
void H5Format::write_attribute(H5::H5Object& target, const string& name, int value)
{
H5::DataSpace att_space(H5S_SCALAR);
auto data_type = H5::PredType::NATIVE_INT;
@@ -213,7 +213,7 @@ void H5Format::write_attribute(H5::H5Object& target, string name, int value)
h5_attribute.write(data_type, &value);
}
void H5Format::write_attribute(H5::H5Object& target, h5_attr& attribute, map<string, boost::any>& values)
void H5Format::write_attribute(H5::H5Object& target, const h5_attr& attribute, const map<string, boost::any>& values)
{
string name = attribute.name;
boost::any value;
@@ -259,10 +259,10 @@ void H5Format::write_attribute(H5::H5Object& target, h5_attr& attribute, map<str
}
}
void H5Format::write_format_data(H5::Group& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values) {
void H5Format::write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map<std::string, h5_value>& values) {
auto node_group = H5Format::create_group(file_node, format_node.name);
for (auto item : format_node.items) {
for (const auto item : format_node.items) {
if (item->node_type == GROUP) {
auto sub_group = dynamic_cast<h5_group*>(item);
@@ -276,7 +276,7 @@ void H5Format::write_format_data(H5::Group& file_node, h5_parent& format_node, s
auto sub_dataset = dynamic_cast<h5_dataset*>(item);
auto current_dataset = H5Format::write_dataset(node_group, *sub_dataset, values);
for (auto dataset_attr : sub_dataset->items) {
for (const auto dataset_attr : sub_dataset->items) {
// You can specify only attributes inside a dataset.
if (dataset_attr->node_type != ATTRIBUTE) {
@@ -294,7 +294,7 @@ void H5Format::write_format_data(H5::Group& file_node, h5_parent& format_node, s
}
}
void H5Format::write_format(H5::H5File& file, std::map<std::string, h5_value>& input_values, string frames_dataset_name){
void H5Format::write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values, const string& frames_dataset_name){
auto format = get_format_definition();
auto values = get_default_values();
+17 -17
View File
@@ -67,33 +67,33 @@ struct h5_attr : public h5_base, public h5_data_base {
};
namespace H5Format {
hsize_t expand_dataset(const H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step);
void compact_dataset(const H5::DataSet& dataset, hsize_t max_frame_index);
hsize_t expand_dataset(H5::DataSet& dataset, hsize_t frame_index, hsize_t dataset_increase_step);
void compact_dataset(H5::DataSet& dataset, hsize_t max_frame_index);
H5::Group create_group(H5::Group& target, std::string name);
H5::PredType get_dataset_data_type(std::string& type);
H5::Group create_group(H5::Group& target, const std::string& name);
H5::PredType get_dataset_data_type(const std::string& type);
H5::DataSet write_dataset(H5::Group& target, h5_dataset& dataset, std::map<std::string, boost::any>& values);
H5::DataSet write_dataset(H5::Group& target, std::string name, double value);
H5::DataSet write_dataset(H5::Group& target, std::string name, int value);
H5::DataSet write_dataset(H5::Group& target, std::string name, std::string value);
H5::DataSet write_dataset(H5::Group& target, const h5_dataset& dataset, const std::map<std::string, boost::any>& values);
H5::DataSet write_dataset(H5::Group& target, const std::string& name, double value);
H5::DataSet write_dataset(H5::Group& target, const std::string& name, int value);
H5::DataSet write_dataset(H5::Group& target, const std::string& name, const std::string& value);
void write_attribute(H5::H5Object& target, h5_attr& attribute, std::map<std::string, boost::any>& values);
void write_attribute(H5::H5Object& target, std::string name, std::string value);
void write_attribute(H5::H5Object& target, std::string name, int value);
void write_attribute(H5::H5Object& target, const h5_attr& attribute, const std::map<std::string, boost::any>& values);
void write_attribute(H5::H5Object& target, const std::string& name, const std::string& value);
void write_attribute(H5::H5Object& target, const std::string& name, int value);
boost::any get_value_from_reference(std::string& dataset_name, boost::any value_reference, std::map<std::string, boost::any>& values);
const boost::any& get_value_from_reference(const std::string& dataset_name, const boost::any& value_reference, const std::map<std::string, boost::any>& values);
void write_format_data(H5::Group& file_node, h5_parent& format_node, std::map<std::string, h5_value>& values);
void write_format(H5::H5File& file, std::map<std::string, h5_value>& input_values, std::string frames_dataset_name);
void write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map<std::string, h5_value>& values);
void write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values, const std::string& frames_dataset_name);
};
// Move this somewhere else.
std::map<std::string, DATA_TYPE>* get_input_value_type();
const std::map<std::string, DATA_TYPE>* get_input_value_type();
std::map<std::string, boost::any>* get_default_values();
h5_group* get_format_definition();
const h5_group* get_format_definition();
void add_calculated_values(std::map<std::string, boost::any>& values);
void add_input_values(std::map<std::string, boost::any>& values, std::map<std::string, boost::any>& input_values);
void add_input_values(std::map<std::string, boost::any>& values, const std::map<std::string, boost::any>& input_values);
std::string get_frames_dataset_name();
#endif
+4 -4
View File
@@ -12,7 +12,7 @@ extern "C"
using namespace std;
H5Writer::H5Writer(const std::string filename, const std::string dataset_name,
H5Writer::H5Writer(const std::string& filename, const std::string& dataset_name,
hsize_t frames_per_file, hsize_t initial_dataset_size, hsize_t dataset_increase_step) :
filename(filename), dataset_name(dataset_name), frames_per_file(frames_per_file),
initial_dataset_size(initial_dataset_size), dataset_increase_step(dataset_increase_step)
@@ -74,7 +74,7 @@ void H5Writer::close_file()
max_frame_index = 0;
}
void H5Writer::write_frame_data(size_t frame_index, size_t* frame_shape, size_t data_bytes_size, char* data, string data_type, string endianness)
void H5Writer::write_frame_data(size_t frame_index, const size_t* frame_shape, size_t data_bytes_size, const char* data, const string& data_type, const string& endianness)
{
// Define the ofset of the currently received image in the file.
hsize_t relative_frame_index = prepare_storage_for_frame(frame_index, frame_shape, data_type, endianness);
@@ -92,7 +92,7 @@ void H5Writer::write_frame_data(size_t frame_index, size_t* frame_shape, size_t
}
}
void H5Writer::create_file(size_t* frame_shape, hsize_t frame_chunk, string& type, string& endianness)
void H5Writer::create_file(const size_t* frame_shape, hsize_t frame_chunk, const string& type, const string& endianness)
{
if (file.getId() != -1) {
@@ -162,7 +162,7 @@ bool H5Writer::is_file_open()
return (file.getId() != -1);
}
hsize_t H5Writer::prepare_storage_for_frame(size_t frame_index, size_t* frame_shape, string& data_type, string& endianness)
hsize_t H5Writer::prepare_storage_for_frame(size_t frame_index, const size_t* frame_shape, const string& data_type, const string& endianness)
{
hsize_t relative_frame_index = frame_index;
+7 -7
View File
@@ -7,8 +7,8 @@
class H5Writer
{
// Initialized in constructor.
std::string filename;
std::string dataset_name;
const std::string filename;
const std::string dataset_name;
hsize_t frames_per_file;
hsize_t initial_dataset_size;
hsize_t dataset_increase_step = 0;
@@ -21,17 +21,17 @@ class H5Writer
H5::H5File file;
H5::DataSet dataset;
hsize_t prepare_storage_for_frame(size_t frame_index, size_t* frame_shape, std::string& data_type, std::string& endianness);
void create_file(size_t* frame_shape, hsize_t frame_chunk, std::string& data_type, std::string& endianness);
hsize_t prepare_storage_for_frame(size_t frame_index, const size_t* frame_shape, const std::string& data_type, const std::string& endianness);
void create_file(const size_t* frame_shape, hsize_t frame_chunk, const std::string& data_type, const std::string& endianness);
public:
H5Writer(const std::string filename, const std::string dataset_name,
H5Writer(const std::string& filename, const std::string& dataset_name,
hsize_t frames_per_file=0, hsize_t initial_dataset_size=1000, hsize_t dataset_increase_step=1000);
~H5Writer();
bool is_file_open();
void close_file();
void write_frame_data(size_t frame_index, size_t* frame_shape, size_t data_bytes_size,
char* data, std::string data_type, std::string endianness);
void write_frame_data(size_t frame_index, const size_t* frame_shape, size_t data_bytes_size,
const char* data, const std::string& data_type, const std::string& endianness);
H5::H5File& get_h5_file();
};
+2 -2
View File
@@ -5,7 +5,7 @@
using namespace std;
WriterManager::WriterManager(map<string, DATA_TYPE>* parameters_type, uint64_t n_frames):
WriterManager::WriterManager(const map<string, DATA_TYPE>* parameters_type, uint64_t n_frames):
parameters_type(parameters_type), n_frames(n_frames), running_flag(true), killed_flag(false), n_received_frames(0), n_written_frames(0)
{
#ifdef DEBUG_OUTPUT
@@ -84,7 +84,7 @@ void WriterManager::set_parameters(map<string, boost::any>& new_parameters)
#endif
}
map<string, DATA_TYPE>* WriterManager::get_parameters_type() {
const map<string, DATA_TYPE>* WriterManager::get_parameters_type() {
return parameters_type;
}
+3 -3
View File
@@ -16,7 +16,7 @@ class WriterManager
std::mutex parameters_mutex;
// Initialize in constructor.
std::map<std::string, DATA_TYPE>* parameters_type;
const std::map<std::string, DATA_TYPE>* parameters_type;
size_t n_frames;
std::atomic_bool running_flag;
std::atomic_bool killed_flag;
@@ -24,7 +24,7 @@ class WriterManager
std::atomic<uint64_t> n_written_frames;
public:
WriterManager(std::map<std::string, DATA_TYPE>* parameters_type, uint64_t n_frames=0);
WriterManager(const std::map<std::string, DATA_TYPE>* parameters_type, uint64_t n_frames=0);
void stop();
void kill();
bool is_running();
@@ -32,7 +32,7 @@ class WriterManager
std::string get_status();
bool are_all_parameters_set();
std::map<std::string, DATA_TYPE>* get_parameters_type();
const std::map<std::string, DATA_TYPE>* get_parameters_type();
std::map<std::string, boost::any> get_parameters();
void set_parameters(std::map<std::string, boost::any>& new_parameters);
+2 -2
View File
@@ -196,10 +196,10 @@ int main (int argc, char *argv[])
{
if (argc != 6) {
cout << endl;
cout << "Usage: h5_zmq_writer [connection_address] [output_file] [n_frames] [rest_port]" << endl;
cout << "Usage: h5_zmq_writer [connection_address] [output_file] [n_frames] [rest_port] [user_id]" << endl;
cout << "\tconnection_address: Address to connect to the stream (PULL). Example: tcp://127.0.0.1:40000" << endl;
cout << "\toutput_file: Name of the output file." << endl;
cout << "\n_frames: Number of images to acquire. 0 for infinity (untill /stop is called)." << endl;
cout << "\t_frames: Number of images to acquire. 0 for infinity (untill /stop is called)." << endl;
cout << "\trest_port: Port to start the REST Api on." << endl;
cout << "\tuser_id: uid under which to run the writer. -1 to leave it as it is." << endl;
cout << endl;
+4 -4
View File
@@ -11,7 +11,7 @@ string get_frames_dataset_name() {
return "entry/plottable_data/data";
}
h5_group* get_format_definition(){
const h5_group* get_format_definition(){
auto format =
new h5_group("entry", {
@@ -883,7 +883,7 @@ void add_calculated_values(map<string, boost::any>& values){
}
}
void add_input_values(map<string, boost::any>& values, map<string, boost::any>& input_values) {
void add_input_values(map<string, boost::any>& values, const map<string, boost::any>& input_values) {
map<string, list<string>> input_mapping = {
{"sl2wv", {"slit_2/y_gap"}},
{"sl0ch", {"slit_0/x_translation"}},
@@ -956,12 +956,12 @@ void add_input_values(map<string, boost::any>& values, map<string, boost::any>&
for (auto input : input_mapping) {
for (auto destination_name : input.second) {
values[destination_name] = input_values[input.first];
values[destination_name] = input_values.at(input.first);
}
}
}
std::map<string, DATA_TYPE>* get_input_value_type() {
const std::map<string, DATA_TYPE>* get_input_value_type() {
auto input_value_types = new std::map<string, DATA_TYPE>({
{"sl2wv", NX_FLOAT},
{"sl0ch", NX_FLOAT},