Code style improvements

This commit is contained in:
2018-01-31 15:51:26 +01:00
parent 3054328a40
commit a5a65b1e7f
4 changed files with 41 additions and 23 deletions
+9 -5
View File
@@ -72,8 +72,8 @@ const boost::any& H5FormatUtils::get_value_from_reference(const string& dataset_
}
}
H5::PredType H5FormatUtils::get_dataset_data_type(const string& type){
H5::PredType H5FormatUtils::get_dataset_data_type(const string& type)
{
#ifdef DEBUG_OUTPUT
cout << "[H5FormatUtils::get_dataset_data_type] Getting dataset type for received frame type " << type << endl;
#endif
@@ -105,7 +105,8 @@ H5::PredType H5FormatUtils::get_dataset_data_type(const string& type){
}
}
H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& dataset, const map<string, boost::any>& values){
H5::DataSet H5FormatUtils::write_dataset(H5::Group& target, const h5_dataset& dataset, const map<string, boost::any>& values)
{
string name = dataset.name;
boost::any value;
@@ -259,7 +260,8 @@ void H5FormatUtils::write_attribute(H5::H5Object& target, const h5_attr& attribu
}
}
void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map<std::string, h5_value>& values) {
void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& format_node, const std::map<std::string, h5_value>& values)
{
auto node_group = H5FormatUtils::create_group(file_node, format_node.name);
for (const auto item : format_node.items) {
@@ -294,7 +296,9 @@ void H5FormatUtils::write_format_data(H5::Group& file_node, const h5_parent& for
}
}
void H5FormatUtils::write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values, const string& raw_frames_dataset_name, const string& frames_dataset_name){
void H5FormatUtils::write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values,
const string& raw_frames_dataset_name, const string& frames_dataset_name)
{
auto format = get_format_definition();
auto values = get_default_values();
+20 -11
View File
@@ -10,13 +10,15 @@
typedef boost::any h5_value;
enum NODE_TYPE {
enum NODE_TYPE
{
ATTRIBUTE,
DATASET,
GROUP
};
enum DATA_TYPE {
enum DATA_TYPE
{
NX_FLOAT,
NX_CHAR,
NX_INT,
@@ -25,48 +27,56 @@ enum DATA_TYPE {
NXnote
};
enum DATA_LOCATION {
enum DATA_LOCATION
{
IMMEDIATE,
REFERENCE
};
struct h5_base {
struct h5_base
{
h5_base(const std::string& name, NODE_TYPE node_type) : name(name), node_type(node_type){};
virtual ~h5_base(){};
std::string name;
NODE_TYPE node_type;
};
struct h5_data_base{
struct h5_data_base
{
h5_data_base(DATA_TYPE data_type, DATA_LOCATION data_location) : data_type(data_type), data_location(data_location) {};
DATA_TYPE data_type;
DATA_LOCATION data_location;
};
struct h5_parent: public h5_base{
struct h5_parent: public h5_base
{
h5_parent(const std::string& name, NODE_TYPE node_type, const std::list<h5_base*>& items) : h5_base(name, node_type), items(items) {};
std::list<h5_base*> items;
};
struct h5_group : public h5_parent {
struct h5_group : public h5_parent
{
h5_group(const std::string& name, const std::list<h5_base*>& items) : h5_parent(name, GROUP, items) {};
};
struct h5_dataset : public h5_parent, public h5_data_base{
struct h5_dataset : public h5_parent, public h5_data_base
{
h5_dataset(const std::string& name, const std::string& value, DATA_TYPE data_type, const std::list<h5_base*>& items={})
: h5_parent(name, DATASET, items), h5_data_base(data_type, REFERENCE), value(value) {};
std::string value;
};
struct h5_attr : public h5_base, public h5_data_base {
struct h5_attr : public h5_base, public h5_data_base
{
h5_attr(const std::string& name, const h5_value& value, DATA_TYPE data_types, DATA_LOCATION data_location=IMMEDIATE)
: h5_base(name, ATTRIBUTE), h5_data_base(data_types, data_location), value(value){};
h5_value value;
};
namespace H5FormatUtils {
namespace H5FormatUtils
{
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);
@@ -88,7 +98,6 @@ namespace H5FormatUtils {
void write_format(H5::H5File& file, const std::map<std::string, h5_value>& input_values, const std::string& raw_frames_dataset_name, const std::string& frames_dataset_name);
};
// Move this somewhere else.
const std::map<std::string, DATA_TYPE>* get_input_value_type();
std::map<std::string, boost::any>* get_default_values();
+10 -5
View File
@@ -8,13 +8,15 @@
using namespace std;
RingBuffer::RingBuffer(size_t n_slots) : n_slots(n_slots), ringbuffer_slots(n_slots, 0){
RingBuffer::RingBuffer(size_t n_slots) : n_slots(n_slots), ringbuffer_slots(n_slots, 0)
{
#ifdef DEBUG_OUTPUT
cout << "[RingBuffer::RingBuffer] Creating ring buffer with n_slots " << n_slots << endl;
#endif
}
RingBuffer::~RingBuffer() {
RingBuffer::~RingBuffer()
{
// If the frame buffer is allocated, free it.
if (frame_data_buffer != NULL) {
free(frame_data_buffer);
@@ -115,7 +117,8 @@ void RingBuffer::write(FrameMetadata &frame_metadata, const char* data)
#endif
}
char* RingBuffer::get_buffer_slot_address(size_t buffer_slot_index) {
char* RingBuffer::get_buffer_slot_address(size_t buffer_slot_index)
{
char* slot_memory_address = frame_data_buffer + (buffer_slot_index * slot_size);
// Check if the memory address is valid.
@@ -175,7 +178,8 @@ pair<FrameMetadata, char*> RingBuffer::read()
return {frame_metadata, slot_memory_address};
}
void RingBuffer::release(size_t buffer_slot_index) {
void RingBuffer::release(size_t buffer_slot_index)
{
// Cannot release a slot index that is out of range.
if (buffer_slot_index >= n_slots) {
stringstream error_message;
@@ -204,7 +208,8 @@ void RingBuffer::release(size_t buffer_slot_index) {
ringbuffer_slots_mutex.unlock();
}
bool RingBuffer::is_empty(){
bool RingBuffer::is_empty()
{
ringbuffer_slots_mutex.lock();
bool is_empty = buffer_used_slots == 0;
+2 -2
View File
@@ -159,8 +159,8 @@ void receive_zmq(WriterManager& manager, RingBuffer& ring_buffer, string connect
#endif
}
void run_writer(string connect_address, string output_file, uint64_t n_frames, uint16_t rest_port){
void run_writer(string connect_address, string output_file, uint64_t n_frames, uint16_t rest_port)
{
size_t n_slots = config::ring_buffer_n_slots;
int n_io_threads = config::zmq_n_io_threads;
int receive_timeout = config::zmq_receive_timeout;