[ismrmrd] 36/177: Changed C++ API. Headers are now structs with just a few methods.

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Wed Jan 14 20:01:59 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to annotated tag v1.1.0.beta.1
in repository ismrmrd.

commit a68052112d13759dadfad830fe2fdaf8ead7d601
Author: Souheil Inati <souheil.inati at nih.gov>
Date:   Tue Sep 2 12:33:44 2014 -0400

    Changed C++ API.  Headers are now structs with just a few methods.
---
 examples/c++/basic_test.cpp |  19 ++--
 ismrmrd.cpp                 | 253 ++------------------------------------------
 ismrmrd.h                   |  74 +------------
 ismrmrd_dataset.cpp         |   2 +-
 ismrmrd_dataset.h           |   3 +-
 5 files changed, 28 insertions(+), 323 deletions(-)

diff --git a/examples/c++/basic_test.cpp b/examples/c++/basic_test.cpp
index 2943974..a5fa77e 100644
--- a/examples/c++/basic_test.cpp
+++ b/examples/c++/basic_test.cpp
@@ -8,23 +8,24 @@ int main (int args, char** argv) {
   using namespace ISMRMRD;
   
   AcquisitionHeader acqhdr;
-  std::cout << "Version: " << acqhdr.version() << std::endl;
-  std::cout << "Flags 0: " << acqhdr.flags() << std::endl;
+  std::cout << "Version: " << acqhdr.version << std::endl;
+  std::cout << "Flags 0: " << acqhdr.flags << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
   acqhdr.setFlag(ISMRMRD_ACQ_FIRST_IN_SLICE);
-  std::cout << "Flags 1: " << acqhdr.flags() << std::endl;
+  std::cout << "Flags 1: " << acqhdr.flags << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
   acqhdr.clearFlag(ISMRMRD_ACQ_FIRST_IN_SLICE);
-  std::cout << "Flags 2: " << acqhdr.flags() << std::endl;
+  std::cout << "Flags 2: " << acqhdr.flags << std::endl;
   std::cout << "ACQ_FIRST_IN_SLICE: " << acqhdr.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
 
-  // How to use the AcquisitionHeader as a wrapper to the C struct.
+  // The C++ AcquisitionHeader can be mem copied from the C struct ISMRMRD_AcquisitionHeader
   ISMRMRD_AcquisitionHeader c_acqhdr;
   ismrmrd_init_acquisition_header(&c_acqhdr);
   c_acqhdr.flags = 64;
-  
-  AcquisitionHeader acqhdr2(&c_acqhdr);
-  std::cout << "AcquisitionHeader copy: flags: " << acqhdr2.flags() << std::endl;
+
+  AcquisitionHeader acqhdr2;
+  memcpy(&acqhdr2, &c_acqhdr, sizeof(AcquisitionHeader));
+  std::cout << "AcquisitionHeader copy: flags: " << acqhdr2.flags << std::endl;
   
   Acquisition acq;
   std::cout << "Version: " << acq.version() << std::endl;
@@ -46,7 +47,7 @@ int main (int args, char** argv) {
   std::cout << "Acquisition copy ACQ_FIRST_IN_SLICE: " << acq2.isFlagSet(ISMRMRD_ACQ_FIRST_IN_SLICE) << std::endl;
   std::cout << "Acquisition nsamp: " << acq.number_of_samples() << "    Acquisition copy nsamp: " << acq2.number_of_samples() << std::endl;
  
-  // How to use the Acquisition as a wrapper to the C struct.
+  // How to use the C++ Acquisition as a wrapper to the C struct ISMRMRD_Acquistion
   ISMRMRD_Acquisition c_acq;
   ismrmrd_init_acquisition(&c_acq);
   c_acq.head.number_of_samples = 128;
diff --git a/ismrmrd.cpp b/ismrmrd.cpp
index da55f40..e375e41 100644
--- a/ismrmrd.cpp
+++ b/ismrmrd.cpp
@@ -10,125 +10,24 @@ namespace ISMRMRD {
 //
 // Constructors
 AcquisitionHeader::AcquisitionHeader() {
-    ismrmrd_init_acquisition_header(&head_);
-};
-
-AcquisitionHeader::AcquisitionHeader(const ISMRMRD_AcquisitionHeader *head) {
-    memcpy(&head_, head, sizeof(ISMRMRD_AcquisitionHeader));
-};
-
-// Accessors and mutators
-const uint16_t &AcquisitionHeader::version() {
-    return head_.version;
-};
-
-const uint64_t &AcquisitionHeader::flags() {
-    return head_.flags;
-};
-
-uint32_t &AcquisitionHeader::measurement_uid() {
-    return head_.measurement_uid;
-};
-
-uint32_t &AcquisitionHeader::scan_counter() {
-    return head_.scan_counter;
-};
-
-uint32_t &AcquisitionHeader::acquisition_time_stamp() {
-    return head_.acquisition_time_stamp;
-};
-
-uint32_t (&AcquisitionHeader::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] {
-    return head_.physiology_time_stamp;
-};
-
-uint16_t &AcquisitionHeader::number_of_samples() {
-    return head_.number_of_samples;
-};
-
-uint16_t &AcquisitionHeader::available_channels() {
-    return head_.available_channels;
-};
-
-uint16_t &AcquisitionHeader::active_channels() {
-    return head_.active_channels;
-};
-
-const uint64_t (&AcquisitionHeader::channel_mask()) [ISMRMRD_CHANNEL_MASKS] { 
-    return head_.channel_mask;
-};
-
-uint16_t &AcquisitionHeader::discard_pre() {
-    return head_.discard_pre;
-};
-
-uint16_t &AcquisitionHeader::discard_post() {
-    return head_.discard_post;
-};
-
-uint16_t &AcquisitionHeader::center_sample() {
-    return head_.center_sample;
-};
-
-uint16_t &AcquisitionHeader::encoding_space_ref() {
-    return head_.encoding_space_ref;
-};
-
-uint16_t &AcquisitionHeader::trajectory_dimensions() {
-    return head_.trajectory_dimensions;
-};
-
-float &AcquisitionHeader::sample_time_us() {
-    return head_.sample_time_us;
-};
-
-float (&AcquisitionHeader::position())[3] {
-    return head_.position;
-};
-
-float (&AcquisitionHeader::read_dir())[3] {
-    return head_.read_dir;
-};
-
-float (&AcquisitionHeader::phase_dir())[3] {
-    return head_.phase_dir;
-};
-
-float (&AcquisitionHeader::slice_dir())[3] {
-    return head_.slice_dir;
-};
-
-float (&AcquisitionHeader::patient_table_position())[3] {
-    return head_.patient_table_position;
-};
-
-ISMRMRD_EncodingCounters &AcquisitionHeader::idx() {
-    return head_.idx;
-};
-
-int32_t (&AcquisitionHeader::user_int()) [ISMRMRD_USER_INTS] { 
-    return head_.user_int;
-};
-
-float (&AcquisitionHeader::user_float()) [ISMRMRD_USER_FLOATS] {
- return head_.user_float;
+    ismrmrd_init_acquisition_header(this);
 };
 
 // Flag methods
 bool AcquisitionHeader::isFlagSet(const ISMRMRD_AcquisitionFlags val) {
-    return ismrmrd_is_flag_set(head_.flags, val);
+    return ismrmrd_is_flag_set(flags, val);
 };
 
 void AcquisitionHeader::setFlag(const ISMRMRD_AcquisitionFlags val) {
-    ismrmrd_set_flag(&(head_.flags), val);
+    ismrmrd_set_flag(&flags, val);
 };
 
 void AcquisitionHeader::clearFlag(const ISMRMRD_AcquisitionFlags val) {
-    ismrmrd_clear_flag(&(head_.flags), val);
+    ismrmrd_clear_flag(&flags, val);
 };
 
 void AcquisitionHeader::clearAllFlags() {
-    ismrmrd_clear_all_flags(&(head_.flags));
+    ismrmrd_clear_all_flags(&flags);
 };
 
 // TODO: Channel mask methods go here
@@ -295,156 +194,26 @@ void Acquisition::clearAllFlags() {
 // ImageHeader class Implementation
 //
 
-// Constructors
+// Constructor
 ImageHeader::ImageHeader() {
-    ismrmrd_init_image_header(&head_);
-};
-
-// Accessors and mutators
-const uint16_t &ImageHeader::version() {
-    return head_.version;
-};
-const uint16_t &ImageHeader::data_type() {
-    return head_.data_type;
-};
-void ImageHeader::data_type(uint16_t dtype) {
-    // TODO function to check if type is valid
-    head_.data_type = dtype;
-};
-
-const uint64_t &ImageHeader::flags() {
-    return head_.flags;
-};
-
-uint32_t &ImageHeader::measurement_uid() {
-    return head_.measurement_uid;
-};
-
-const uint16_t (&ImageHeader::matrix_size())[3] {
-    return head_.matrix_size;
-};
-
-void ImageHeader::matrix_size(const uint16_t msize[3]) {
-    head_.matrix_size[0] = msize[0];
-    if (msize[1] > 1) {
-        head_.matrix_size[1] = msize[1];
-    } else {
-        head_.matrix_size[1] = 1;
-    }
-    if (msize[2] > 0) {
-        head_.matrix_size[2] = msize[2];
-    } else {
-        head_.matrix_size[2] = 1;
-    }
-};
-
-float (&ImageHeader::field_of_view())[3] {
-    return head_.field_of_view;
-};
-
-const uint16_t &ImageHeader::channels() {
-    return head_.channels;
-};
-
-void ImageHeader::channels(const uint16_t num_channels) {
-    if (num_channels > 1) {
-        head_.channels = num_channels;
-    } else {
-        head_.channels = 1;
-    }
-};
-
-float (&ImageHeader::position())[3] {
-    return head_.position;
-};
-
-float (&ImageHeader::read_dir())[3] {
-    return head_.read_dir;
-};
-
-float (&ImageHeader::phase_dir())[3] {
-    return head_.phase_dir;
-};
-
-float (&ImageHeader::slice_dir())[3] {
-    return head_.slice_dir;
-};
-
-float (&ImageHeader::patient_table_position())[3] {
-    return head_.patient_table_position;
-};
-
-uint16_t &ImageHeader::average() {
-    return head_.average;
-};
-
-uint16_t &ImageHeader::slice() {
-    return head_.slice;
-};
-
-uint16_t &ImageHeader::contrast() {
-    return head_.contrast;
-};
-
-uint16_t &ImageHeader::phase() {
-    return head_.repetition;
-};
-
-uint16_t &ImageHeader::repetition() {
-    return head_.repetition;
-};
-
-uint16_t &ImageHeader::set() {
-    return head_.set;
-};
-
-uint32_t &ImageHeader::acquisition_time_stamp() {
-    return head_.acquisition_time_stamp;
-};
-
-uint32_t (&ImageHeader::physiology_time_stamp()) [ISMRMRD_PHYS_STAMPS] {
-    return head_.physiology_time_stamp;
-};
-
-uint16_t &ImageHeader::image_type() {
-    return head_.image_type;
-};
-
-uint16_t &ImageHeader::image_index() {
-    return head_.image_index;
-};
-
-uint16_t &ImageHeader::image_series_index() {
-    return head_.image_series_index;
-};
-
-int32_t (&ImageHeader::user_int()) [ISMRMRD_USER_INTS] { 
-    return head_.user_int;
-};
-
-float (&ImageHeader::user_float()) [ISMRMRD_USER_FLOATS] { 
-    return head_.user_float;
-};
-
-const uint32_t &ImageHeader::attribute_string_len() {
-    return head_.attribute_string_len;
+    ismrmrd_init_image_header(this);
 };
 
 // Flag methods
 bool ImageHeader::isFlagSet(const uint64_t val) {
-    return ismrmrd_is_flag_set(head_.flags, val);
+    return ismrmrd_is_flag_set(flags, val);
 };
 
 void ImageHeader::setFlag(const uint64_t val) {
-    ismrmrd_set_flag(&(head_.flags), val);
+    ismrmrd_set_flag(&flags, val);
 };
 
 void ImageHeader::clearFlag(const uint64_t val) {
-    ismrmrd_clear_flag(&(head_.flags), val);
+    ismrmrd_clear_flag(&flags, val);
 };
 
 void ImageHeader::clearAllFlags() {
-    ismrmrd_clear_all_flags(&(head_.flags));
+    ismrmrd_clear_all_flags(&flags);
 };
 
 //
diff --git a/ismrmrd.h b/ismrmrd.h
index afc9b58..f78cd02 100644
--- a/ismrmrd.h
+++ b/ismrmrd.h
@@ -30,6 +30,7 @@ typedef unsigned __int64 uint64_t;
 typedef std::complex<float> complex_float_t;
 typedef std::complex<double> complex_double_t;
 #include <vector>
+
 #else /* C99 compiler */
 #include <stdint.h>
 #include <complex.h>
@@ -341,41 +342,11 @@ void ismrmrd_quaternion_to_directions(float quat[4], float read_dir[3], float ph
 // TODO:
 // - exports for all the classes
 
-class AcquisitionHeader {
+class AcquisitionHeader: public ISMRMRD_AcquisitionHeader {
 public:
     // Constructors
     AcquisitionHeader();
-    AcquisitionHeader(const ISMRMRD_AcquisitionHeader *head);
-
-    // TODO
-    // Do we need to define an assignment operator?
     
-    // Accessors and mutators
-    const uint16_t &version();
-    const uint64_t &flags();
-    uint32_t &measurement_uid();
-    uint32_t &scan_counter();
-    uint32_t &acquisition_time_stamp();
-    uint32_t (&physiology_time_stamp())[ISMRMRD_PHYS_STAMPS];
-    uint16_t &number_of_samples();
-    uint16_t &available_channels();
-    uint16_t &active_channels();
-    const uint64_t (&channel_mask())[ISMRMRD_CHANNEL_MASKS];
-    uint16_t &discard_pre();
-    uint16_t &discard_post();
-    uint16_t &center_sample();
-    uint16_t &encoding_space_ref();
-    uint16_t &trajectory_dimensions();
-    float &sample_time_us();
-    float (&position())[3];
-    float (&read_dir())[3];
-    float (&phase_dir())[3];
-    float (&slice_dir())[3];
-    float (&patient_table_position())[3];
-    ISMRMRD_EncodingCounters &idx();
-    int32_t (&user_int())[ISMRMRD_USER_INTS];
-    float (&user_float())[ISMRMRD_USER_FLOATS];
-
     // Flag methods
     bool isFlagSet(const ISMRMRD_AcquisitionFlags val);
     void setFlag(const ISMRMRD_AcquisitionFlags val);
@@ -389,8 +360,6 @@ public:
     //void setChannelNotActive(uint16_t channel_id);
     //void setAllChannelsNotActive();
 
-protected:
-    ISMRMRD_AcquisitionHeader head_;
 };
 
 class Acquisition {
@@ -454,43 +423,10 @@ protected:
     ISMRMRD_Acquisition acq_;
 };
 
-class ImageHeader {
+class ImageHeader: public ISMRMRD_ImageHeader {
 public:
-    // Constructors
+    // Constructor
     ImageHeader();
-    ImageHeader(ImageHeader &hdr);
-    ImageHeader(ISMRMRD_ImageHeader *hdr);
-
-    // Accessors and mutators
-    const uint16_t &version();
-    const uint16_t &data_type();
-    void data_type(uint16_t dtype);
-    const uint64_t &flags();
-    uint32_t &measurement_uid();
-    const uint16_t (&matrix_size())[3];
-    void matrix_size(const uint16_t msize[3]);
-    float (&field_of_view())[3];
-    const uint16_t &channels();
-    void channels(const uint16_t num_channels);
-    float (&position())[3];
-    float (&read_dir())[3];
-    float (&phase_dir())[3];
-    float (&slice_dir())[3];
-    float (&patient_table_position())[3];
-    uint16_t &average();
-    uint16_t &slice();
-    uint16_t &contrast();
-    uint16_t &phase();
-    uint16_t &repetition();
-    uint16_t &set();
-    uint32_t &acquisition_time_stamp();
-    uint32_t (&physiology_time_stamp())[ISMRMRD_PHYS_STAMPS];
-    uint16_t &image_type();
-    uint16_t &image_index();
-    uint16_t &image_series_index();
-    int32_t (&user_int())[ISMRMRD_USER_INTS];
-    float (&user_float())[ISMRMRD_USER_FLOATS];
-    const uint32_t &attribute_string_len();
 
     // Flag methods
     bool isFlagSet(const uint64_t val);
@@ -498,8 +434,6 @@ public:
     void clearFlag(const uint64_t val);
     void clearAllFlags();
 
-protected:
-    ISMRMRD_ImageHeader head_;
 };
 
 class Image {
diff --git a/ismrmrd_dataset.cpp b/ismrmrd_dataset.cpp
index f641d25..9d02745 100644
--- a/ismrmrd_dataset.cpp
+++ b/ismrmrd_dataset.cpp
@@ -26,7 +26,7 @@ Dataset::~Dataset()
 }
 
 // XML Header
-int Dataset::writeHeader(const std::string& xmlstring)
+int Dataset::writeHeader(const std::string xmlstring)
 {
     int status = ismrmrd_write_header(&dset_, xmlstring.c_str());
     return status;
diff --git a/ismrmrd_dataset.h b/ismrmrd_dataset.h
index 1f589de..ba23507 100644
--- a/ismrmrd_dataset.h
+++ b/ismrmrd_dataset.h
@@ -7,6 +7,7 @@
 #include "ismrmrd.h"
 
 #ifdef __cplusplus
+#include <string>
 namespace ISMRMRD {
 extern "C" {
 #endif
@@ -161,7 +162,7 @@ public:
     
     // Methods
     // XML Header
-    int writeHeader(const std::string& xmlstring);
+    int writeHeader(const std::string xmlstring);
     int writeHeader(const char* xml);
     int readHeader(std::string& xmlstring);
     char * readHeader();

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/ismrmrd.git



More information about the debian-science-commits mailing list