Browse Source

setting up proper code formating + formating the code

Patrik Kovacs 6 years ago
parent
commit
23e19da319

+ 43 - 0
.clang-format

@@ -0,0 +1,43 @@
+AccessModifierOffset: -2
+AlignEscapedNewlinesLeft: true
+AlignTrailingComments: true
+AllowAllParametersOfDeclarationOnNextLine: false
+AllowShortFunctionsOnASingleLine: false
+AllowShortIfStatementsOnASingleLine: false
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakBeforeMultilineStrings: false
+AlwaysBreakTemplateDeclarations: false
+BinPackParameters: false
+BreakBeforeBinaryOperators: false
+
+BreakBeforeBraces: Custom
+BraceWrapping:
+    AfterClass: false
+    AfterControlStatement: false
+    AfterEnum: false
+    AfterFunction: false
+    AfterNamespace: false
+    AfterStruct: false
+    AfterUnion: false
+    BeforeCatch: false
+    BeforeElse: false
+
+BreakBeforeTernaryOperators: false
+BreakConstructorInitializersBeforeComma: true
+
+Cpp11BracedListStyle: true
+
+ColumnLimit: 120
+CommentPragmas: ''
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 0
+IndentCaseLabels: false
+IndentFunctionDeclarationAfterType: false
+IndentWidth: 4
+Language: Cpp
+MaxEmptyLinesToKeep: 2
+NamespaceIndentation: None
+Standard: Cpp11
+TabWidth: 4
+UseTab: Never

+ 22 - 0
format.sh

@@ -0,0 +1,22 @@
+#!/bin/sh
+cd "$(dirname "$0")"
+
+if [ -z "${CLANG_FORMAT_CMD}" ]
+then
+    if [ -x "$(which clang-format-4.0 2> /dev/null)" ]
+    then
+        CLANG_FORMAT_CMD=clang-format-4.0
+    else
+        CLANG_FORMAT_CMD=clang-format
+    fi
+fi
+
+list=`git diff --name-only "HEAD" | grep '\.cpp$\|\.h$'`
+
+for i in ${list}
+do
+  if [ -f "${i}" ] 
+  then 
+	  "${CLANG_FORMAT_CMD}" -i -style=file "${i}" 
+  fi 
+done

+ 21 - 22
include/hdf4cpp/HdfAttribute_priv.h

@@ -1,6 +1,7 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFATTRIBUTE_PRIV_H
 #define HDF4CPP_HDFATTRIBUTE_PRIV_H
 
@@ -10,26 +11,26 @@
 
 #include <hdf/hdf.h>
 #include <hdf/mfhdf.h>
-#include <string>
-#include <vector>
 #include <map>
 #include <memory>
+#include <string>
+#include <vector>
 
 namespace hdf4cpp {
 
 /// The base class of the attribute classes
 class HdfAttribute::HdfAttributeBase : public HdfObject {
   public:
-    HdfAttributeBase(int32 id, int32 index, Type type, const HdfDestroyerChain& chain) : HdfObject(type,
-                                                                                                   ATTRIBUTE,
-                                                                                                   chain),
-                                                                                         id(id),
-                                                                                         index(index) {
+    HdfAttributeBase(int32 id, int32 index, Type type, const HdfDestroyerChain &chain)
+        : HdfObject(type, ATTRIBUTE, chain)
+        , id(id)
+        , index(index) {
         if (id == FAIL || index == FAIL) {
             raiseException(INVALID_ID);
         }
     }
-    virtual ~HdfAttributeBase() {}
+    virtual ~HdfAttributeBase() {
+    }
 
     /// \returns The number of existing data in the attribute
     virtual intn size() const = 0;
@@ -39,7 +40,8 @@ class HdfAttribute::HdfAttributeBase : public HdfObject {
 
     /// Reads the data from the attribute
     /// \param dest The destination vector
-    virtual void get(void* dest) = 0;
+    virtual void get(void *dest) = 0;
+
   protected:
     int32 id;
 
@@ -48,12 +50,12 @@ class HdfAttribute::HdfAttributeBase : public HdfObject {
 
 /// Attribute class for the SData attributes
 class HdfAttribute::HdfDatasetAttribute : public HdfAttributeBase {
-public:
-    HdfDatasetAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain);
+  public:
+    HdfDatasetAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
     intn size() const;
 
-private:
+  private:
     intn _size;
     int32 dataType;
 
@@ -63,12 +65,12 @@ private:
 
 /// Attribute class for the VGroup attributes
 class HdfAttribute::HdfGroupAttribute : public HdfAttributeBase {
-public:
-    HdfGroupAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain);
+  public:
+    HdfGroupAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
     intn size() const;
 
-private:
+  private:
     intn _size;
     int32 dataType;
 
@@ -78,20 +80,17 @@ private:
 
 /// Attribute class for the VData attributes
 class HdfAttribute::HdfDataAttribute : public HdfAttributeBase {
-public:
-    HdfDataAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain);
+  public:
+    HdfDataAttribute(int32 id, const std::string &name, const HdfDestroyerChain &chain);
 
     intn size() const;
 
-private:
+  private:
     intn _size;
     int32 dataType;
     void get(void *dest);
     int32 getDataType() const;
 };
-
-
-
 }
 
-#endif //HDF4CPP_HDFATTRIBUTE_PRIV_H
+#endif // HDF4CPP_HDFATTRIBUTE_PRIV_H

+ 10 - 22
include/hdf4cpp/HdfDefines.h

@@ -1,11 +1,12 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFDEFINES_H
 #define HDF4CPP_HDFDEFINES_H
 
-#include <map>
 #include <hdf/mfhdf.h>
+#include <map>
 
 #define MAX_DIMENSION 32
 #define MAX_NAME_LENGTH 1000
@@ -21,7 +22,7 @@ namespace hdf4cpp {
 /// VGroup type
 /// \var VDATA
 /// VData type
-enum Type {HFILE, SDATA, VGROUP, VDATA};
+enum Type { HFILE, SDATA, VGROUP, VDATA };
 
 /// \enum ClassType
 /// What kind of object it represents:
@@ -33,7 +34,7 @@ enum Type {HFILE, SDATA, VGROUP, VDATA};
 /// attribute
 /// \var ITERATOR
 /// iterator
-enum ClassType {FILE, ITEM, ATTRIBUTE, ITERATOR};
+enum ClassType { FILE, ITEM, ATTRIBUTE, ITERATOR };
 
 /// \enum ExceptionType The type of the HdfException
 enum ExceptionType {
@@ -50,25 +51,12 @@ enum ExceptionType {
 };
 
 const std::multimap<int32, int32> typeSizeMap = {
-        {DFNT_CHAR, SIZE_CHAR},
-        {DFNT_CHAR8, SIZE_CHAR8},
-        {DFNT_CHAR16, SIZE_CHAR16},
-        {DFNT_FLOAT32, SIZE_FLOAT32},
-        {DFNT_FLOAT64, SIZE_FLOAT64},
-        {DFNT_FLOAT128, SIZE_FLOAT128},
-        {DFNT_INT8, SIZE_INT8},
-        {DFNT_INT16, SIZE_INT16},
-        {DFNT_INT32, SIZE_INT32},
-        {DFNT_INT64, SIZE_INT64},
-        {DFNT_UINT8, SIZE_UINT8},
-        {DFNT_UINT16, SIZE_UINT16},
-        {DFNT_UINT32, SIZE_UINT32},
-        {DFNT_UINT64, SIZE_UINT64},
-        {DFNT_UCHAR, SIZE_UCHAR},
-        {DFNT_UCHAR8, SIZE_UCHAR8},
-        {DFNT_UCHAR16, SIZE_UCHAR16},
+{DFNT_CHAR, SIZE_CHAR},       {DFNT_CHAR8, SIZE_CHAR8},       {DFNT_CHAR16, SIZE_CHAR16}, {DFNT_FLOAT32, SIZE_FLOAT32},
+{DFNT_FLOAT64, SIZE_FLOAT64}, {DFNT_FLOAT128, SIZE_FLOAT128}, {DFNT_INT8, SIZE_INT8},     {DFNT_INT16, SIZE_INT16},
+{DFNT_INT32, SIZE_INT32},     {DFNT_INT64, SIZE_INT64},       {DFNT_UINT8, SIZE_UINT8},   {DFNT_UINT16, SIZE_UINT16},
+{DFNT_UINT32, SIZE_UINT32},   {DFNT_UINT64, SIZE_UINT64},     {DFNT_UCHAR, SIZE_UCHAR},   {DFNT_UCHAR8, SIZE_UCHAR8},
+{DFNT_UCHAR16, SIZE_UCHAR16},
 };
-
 }
 
-#endif //HDF4CPP_HDFDEFINES_H
+#endif // HDF4CPP_HDFDEFINES_H

+ 14 - 12
include/hdf4cpp/HdfException.h

@@ -1,6 +1,7 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFEXCEPTION_H
 #define HDF4CPP_HDFEXCEPTION_H
 
@@ -10,14 +11,18 @@ namespace hdf4cpp {
 
 class HdfException : public std::exception {
   public:
-    HdfException(const Type& type, const ClassType& classType, const std::string& message) : type(type),
-                                                                                             classType(classType),
-                                                                                             exceptionType(OTHER),
-                                                                                             message(exceptionMessagePrefix + message) {}
-    HdfException(const Type& type, const ClassType& classType, const ExceptionType& exceptionType) : type(type),
-                                                                                                     classType(classType),
-                                                                                                     exceptionType(exceptionType),
-                                                                                                     message(exceptionMessagePrefix + exceptionTypeMap.at(exceptionType)) {}
+    HdfException(const Type &type, const ClassType &classType, const std::string &message)
+        : type(type)
+        , classType(classType)
+        , exceptionType(OTHER)
+        , message(exceptionMessagePrefix + message) {
+    }
+    HdfException(const Type &type, const ClassType &classType, const ExceptionType &exceptionType)
+        : type(type)
+        , classType(classType)
+        , exceptionType(exceptionType)
+        , message(exceptionMessagePrefix + exceptionTypeMap.at(exceptionType)) {
+    }
     /// Get the Type of the object which threw the exception.
     Type getType() const noexcept;
     /// Get the ClassType of the object which threw the exception.
@@ -33,7 +38,6 @@ class HdfException : public std::exception {
     }
 
   private:
-
     /// Exception message prefix
     static const std::string exceptionMessagePrefix;
     /// Associates the exception type with a specific message
@@ -45,9 +49,7 @@ class HdfException : public std::exception {
     ExceptionType exceptionType;
     std::string message;
 };
-
-
 }
 
 
-#endif //HDF4CPP_HDFEXCEPTION_H
+#endif // HDF4CPP_HDFEXCEPTION_H

+ 32 - 26
include/hdf4cpp/HdfFile.h

@@ -1,6 +1,7 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFFILE_H
 #define HDF4CPP_HDFFILE_H
 
@@ -17,11 +18,11 @@ class HdfAttribute;
 /// Opens an hdf file and provides operations with it
 class HdfFile : public HdfObject {
   public:
-    HdfFile(const std::string& path);
-    HdfFile(const HdfFile& file) = delete;
-    HdfFile(HdfFile&& file);
-    HdfFile& operator=(const HdfFile& file) = delete;
-    HdfFile& operator=(HdfFile&& file);
+    HdfFile(const std::string &path);
+    HdfFile(const HdfFile &file) = delete;
+    HdfFile(HdfFile &&file);
+    HdfFile &operator=(const HdfFile &file) = delete;
+    HdfFile &operator=(HdfFile &&file);
     ~HdfFile();
 
     int32 getSId() const;
@@ -30,15 +31,15 @@ class HdfFile : public HdfObject {
     /// \returns an item from the file with the given name
     /// \param name the name of the item
     /// \note: If there are multiple items with the same name then the first will be returned
-    HdfItem get(const std::string& name) const;
+    HdfItem get(const std::string &name) const;
 
     /// \returns all the items from the file with the given name
     /// \param name the name of the item(s)
-    std::vector<HdfItem> getAll(const std::string& name) const;
+    std::vector<HdfItem> getAll(const std::string &name) const;
 
     /// \returns the attribute with the given name
     /// \param name the name of the attribute
-    HdfAttribute getAttribute(const std::string& name) const;
+    HdfAttribute getAttribute(const std::string &name) const;
 
     class Iterator;
 
@@ -46,31 +47,36 @@ class HdfFile : public HdfObject {
     Iterator end() const;
 
   private:
+    int32 getDatasetId(const std::string &name) const;
+    int32 getGroupId(const std::string &name) const;
+    int32 getDataId(const std::string &name) const;
 
-    int32 getDatasetId(const std::string& name) const;
-    int32 getGroupId(const std::string& name) const;
-    int32 getDataId(const std::string& name) const;
-
-    std::vector<int32> getDatasetIds(const std::string& name) const;
-    std::vector<int32> getGroupDataIds(const std::string& name) const;
+    std::vector<int32> getDatasetIds(const std::string &name) const;
+    std::vector<int32> getGroupDataIds(const std::string &name) const;
 
     int32 sId;
     int32 vId;
 
-    std::vector<std::pair<int32, Type> > loneRefs;
+    std::vector<std::pair<int32, Type>> loneRefs;
 };
 
 /// HdfFile iterator, gives the possibility to iterate over the items in the file
 class HdfFile::Iterator : public HdfObject, public std::iterator<std::bidirectional_iterator_tag, HdfItem> {
-public:
-    Iterator(const HdfFile* file, int32 index, const HdfDestroyerChain& chain) : HdfObject(HFILE, ITERATOR, chain),
-                                                                                 file(file),
-                                                                                 index(index) {}
+  public:
+    Iterator(const HdfFile *file, int32 index, const HdfDestroyerChain &chain)
+        : HdfObject(HFILE, ITERATOR, chain)
+        , file(file)
+        , index(index) {
+    }
 
-    bool operator!=(const Iterator& it) { return index != it.index; }
-    bool operator==(const Iterator& it) { return index == it.index; }
+    bool operator!=(const Iterator &it) {
+        return index != it.index;
+    }
+    bool operator==(const Iterator &it) {
+        return index == it.index;
+    }
 
-    Iterator& operator++() {
+    Iterator &operator++() {
         ++index;
         return *this;
     }
@@ -79,7 +85,7 @@ public:
         ++index;
         return it;
     }
-    Iterator& operator--() {
+    Iterator &operator--() {
         --index;
         return *this;
     }
@@ -90,11 +96,11 @@ public:
     }
 
     HdfItem operator*();
-private:
+
+  private:
     const HdfFile *file;
     int32 index;
 };
-
 }
 
-#endif //HDF4CPP_HDFFILE_H
+#endif // HDF4CPP_HDFFILE_H

+ 107 - 99
include/hdf4cpp/HdfItem.h

@@ -1,18 +1,19 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFITEM_H
 #define HDF4CPP_HDFITEM_H
 
 #include <hdf4cpp/HdfDefines.h>
-#include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfException.h>
+#include <hdf4cpp/HdfFile.h>
 
 #include <algorithm>
+#include <hdf/hdf.h>
 #include <map>
 #include <memory>
 #include <vector>
-#include <hdf/hdf.h>
 
 namespace hdf4cpp {
 
@@ -23,10 +24,15 @@ struct Range {
     int32 begin;
     /// The number of data to be read
     int32 quantity;
-    /// The increasing number (stride = 1 : every data, stride = 2 : every second data, ...)
+    /// The increasing number (stride = 1 : every data, stride = 2 : every second
+    /// data, ...)
     int32 stride;
 
-    Range(int32 begin = 0, int32 quantity = 0, int32 stride = 1) : begin(begin), quantity(quantity), stride(stride) {}
+    Range(int32 begin = 0, int32 quantity = 0, int32 stride = 1)
+        : begin(begin)
+        , quantity(quantity)
+        , stride(stride) {
+    }
 
     /// What would be the number of data to read, if we read in this range
     intn size() const {
@@ -37,16 +43,12 @@ struct Range {
     }
 
     /// Checks if the range is correct for a specific dimension
-    bool check(const int32& dim) const {
-        return begin >= 0 ||
-            begin < dim ||
-            quantity >= 0 ||
-            begin + quantity <= dim ||
-            stride > 0;
+    bool check(const int32 &dim) const {
+        return begin >= 0 || begin < dim || quantity >= 0 || begin + quantity <= dim || stride > 0;
     }
 
     /// Fills a range vector with a dimension array
-    static void fill(std::vector<Range>& ranges, const std::vector<int32>& dims) {
+    static void fill(std::vector<Range> &ranges, const std::vector<int32> &dims) {
         for (size_t i = ranges.size(); i < dims.size(); ++i) {
             ranges.push_back(Range(0, dims[i]));
         }
@@ -57,11 +59,11 @@ class HdfAttribute;
 
 /// Represents an hdf item
 class HdfItem : public HdfObject {
-public:
-    HdfItem(const HdfItem& item) = delete;
-    HdfItem(HdfItem&& item);
-    HdfItem& operator=(const HdfItem& item) = delete;
-    HdfItem& operator=(HdfItem&& it);
+  public:
+    HdfItem(const HdfItem &item) = delete;
+    HdfItem(HdfItem &&item);
+    HdfItem &operator=(const HdfItem &item) = delete;
+    HdfItem &operator=(HdfItem &&it);
 
     /// \returns The name of the item
     std::string getName() const;
@@ -75,35 +77,36 @@ public:
 
     /// \returns the attribute of the item with the given name
     /// \param name the name of the attribute
-    /// \note If there are multiple attributes with the same name then the first will be returned
-    HdfAttribute getAttribute(const std::string& name) const;
+    /// \note If there are multiple attributes with the same name then the first
+    /// will be returned
+    HdfAttribute getAttribute(const std::string &name) const;
 
     /// Reads the entire data from the item
     /// \param dest the destination vector in which the data will be stored
-    template <class T> void read(std::vector<T>& dest) {
-        switch(item->getType()) {
-            case SDATA: {
-                HdfDatasetItem *dItem = dynamic_cast<HdfDatasetItem *>(item.get());
-                dItem->read(dest);
-                break;
-            }
-            default:
-                raiseException(INVALID_OPERATION);
+    template <class T> void read(std::vector<T> &dest) {
+        switch (item->getType()) {
+        case SDATA: {
+            HdfDatasetItem *dItem = dynamic_cast<HdfDatasetItem *>(item.get());
+            dItem->read(dest);
+            break;
+        }
+        default:
+            raiseException(INVALID_OPERATION);
         }
     }
 
     /// Reads the data from the item in a specified range
     /// \param dest the destination vector in which the data will be stored
     /// \param ranges specifies the range in which the data will be read
-    template <class T> void read(std::vector<T>& dest, std::vector<Range> ranges) {
-        switch(item->getType()) {
-            case SDATA: {
-                HdfDatasetItem *dItem = dynamic_cast<HdfDatasetItem *>(item.get());
-                dItem->read(dest, ranges);
-                break;
-            }
-            default:
-                raiseException(INVALID_OPERATION);
+    template <class T> void read(std::vector<T> &dest, std::vector<Range> ranges) {
+        switch (item->getType()) {
+        case SDATA: {
+            HdfDatasetItem *dItem = dynamic_cast<HdfDatasetItem *>(item.get());
+            dItem->read(dest, ranges);
+            break;
+        }
+        default:
+            raiseException(INVALID_OPERATION);
         }
     }
 
@@ -111,15 +114,15 @@ public:
     /// \param dest the destination vector in which the data will be stored
     /// \param field the name of the field
     /// \param records the number of records to be read
-    template <class T> void read(std::vector<T>& dest, const std::string& field, int32 records = 0) {
-        switch(item->getType()) {
-            case VDATA: {
-                HdfDataItem *vItem = dynamic_cast<HdfDataItem*>(item.get());
-                vItem->read(dest, field, records);
-                break;
-            }
-            default:
-                raiseException(INVALID_OPERATION);
+    template <class T> void read(std::vector<T> &dest, const std::string &field, int32 records = 0) {
+        switch (item->getType()) {
+        case VDATA: {
+            HdfDataItem *vItem = dynamic_cast<HdfDataItem *>(item.get());
+            vItem->read(dest, field, records);
+            break;
+        }
+        default:
+            raiseException(INVALID_OPERATION);
         }
     }
 
@@ -127,22 +130,24 @@ public:
     Iterator begin() const;
     Iterator end() const;
 
-    friend HdfItem HdfFile::get(const std::string& name) const;
-    friend std::vector<HdfItem> HdfFile::getAll(const std::string& name) const;
+    friend HdfItem HdfFile::get(const std::string &name) const;
+    friend std::vector<HdfItem> HdfFile::getAll(const std::string &name) const;
     friend HdfItem HdfFile::Iterator::operator*();
     friend class HdfAttribute;
 
-private:
+  private:
     /// The base class of the item classes
     class HdfItemBase : public HdfObject {
-    public:
-
-        HdfItemBase(int32 id, const Type& type, const HdfDestroyerChain& chain) : HdfObject(type, ITEM, chain), id(id) {
+      public:
+        HdfItemBase(int32 id, const Type &type, const HdfDestroyerChain &chain)
+            : HdfObject(type, ITEM, chain)
+            , id(id) {
             if (id == FAIL) {
                 raiseException(INVALID_ID);
             }
         }
-        virtual ~HdfItemBase() {}
+        virtual ~HdfItemBase() {
+        }
 
         /// Get the id which is held by this object
         virtual int32 getId() const = 0;
@@ -153,30 +158,29 @@ private:
         /// Get the number of data from the item
         virtual intn size() const = 0;
         /// Get the attribute from the item given by its name
-        virtual HdfAttribute getAttribute(const std::string& name) const = 0;
+        virtual HdfAttribute getAttribute(const std::string &name) const = 0;
 
-    protected:
+      protected:
         int32 id;
 
         virtual int32 getDataType() const = 0;
     };
     /// Item class for the SData items
     class HdfDatasetItem : public HdfItemBase {
-    public:
-        HdfDatasetItem(int32 id, const HdfDestroyerChain& chain);
+      public:
+        HdfDatasetItem(int32 id, const HdfDestroyerChain &chain);
         ~HdfDatasetItem();
 
         int32 getId() const;
         std::string getName() const;
         std::vector<int32> getDims();
         intn size() const;
-        HdfAttribute getAttribute(const std::string& name) const;
+        HdfAttribute getAttribute(const std::string &name) const;
 
         /// Reads the data in a specific range. See Range
         /// \param dest The destination vector
         /// \param ranges The vector of ranges
-        template <class T>
-        void read(std::vector<T>& dest, std::vector<Range>& ranges) {
+        template <class T> void read(std::vector<T> &dest, std::vector<Range> &ranges) {
             std::vector<int32> dims = getDims();
             Range::fill(ranges, dims);
             intn length = 1;
@@ -196,7 +200,7 @@ private:
             }
             dest.resize(length);
             std::vector<int32> start, quantity, stride;
-            for (const auto& range : ranges) {
+            for (const auto &range : ranges) {
                 start.push_back(range.begin);
                 quantity.push_back(range.quantity);
                 stride.push_back(range.stride);
@@ -209,17 +213,16 @@ private:
 
         /// Reads the whole data
         /// \param dest The destination vector
-        template <class T>
-        void read(std::vector<T>& dest) {
+        template <class T> void read(std::vector<T> &dest) {
             std::vector<int32> dims = getDims();
             std::vector<Range> ranges;
-            for (const auto& dim : dims) {
+            for (const auto &dim : dims) {
                 ranges.push_back(Range(0, dim));
             }
             read(dest, ranges);
         }
 
-    private:
+      private:
         intn _size;
         int32 dataType;
         std::string name;
@@ -229,8 +232,8 @@ private:
     };
     /// Item class for VGroup items
     class HdfGroupItem : public HdfItemBase {
-    public:
-        HdfGroupItem(int32 id, const HdfDestroyerChain& chain);
+      public:
+        HdfGroupItem(int32 id, const HdfDestroyerChain &chain);
         ~HdfGroupItem();
 
         int32 getId() const;
@@ -238,17 +241,17 @@ private:
         std::vector<int32> getDims();
         intn size() const;
 
-        HdfAttribute getAttribute(const std::string& name) const;
+        HdfAttribute getAttribute(const std::string &name) const;
 
-    private:
+      private:
         std::string name;
 
         int32 getDataType() const;
     };
     /// Item class for VData items
     class HdfDataItem : public HdfItemBase {
-    public:
-        HdfDataItem(int32 id, const HdfDestroyerChain& chain);
+      public:
+        HdfDataItem(int32 id, const HdfDestroyerChain &chain);
 
         ~HdfDataItem();
 
@@ -260,15 +263,14 @@ private:
 
         intn size() const;
 
-        HdfAttribute getAttribute(const std::string& name) const;
+        HdfAttribute getAttribute(const std::string &name) const;
 
         /// Reads a specific number of the data of a specific field
         /// The records are simple values
         /// \param dest The destination vector
         /// \param field The specific field name
         /// \param records The number of records to be read
-        template <class T>
-        void read(std::vector<T>& dest, const std::string& field, int32 records) {
+        template <class T> void read(std::vector<T> &dest, const std::string &field, int32 records) {
             if (!records) {
                 records = nrRecords;
             }
@@ -277,8 +279,8 @@ private:
                 raiseException(STATUS_RETURN_FAIL);
             }
 
-            int32 fieldSize = VSsizeof(id, (char*)field.c_str());
-            if (sizeof(T) < (size_t) fieldSize) {
+            int32 fieldSize = VSsizeof(id, (char *)field.c_str());
+            if (sizeof(T) < (size_t)fieldSize) {
                 raiseException(BUFFER_SIZE_NOT_ENOUGH);
             }
 
@@ -291,7 +293,8 @@ private:
             dest.resize(records);
             VOIDP buffptrs[1];
             buffptrs[0] = dest.data();
-            if (VSfpack(id, _HDF_VSUNPACK, field.c_str(), buff.data(), size, records, field.c_str(), buffptrs) == FAIL) {
+            if (VSfpack(id, _HDF_VSUNPACK, field.c_str(), buff.data(), size, records, field.c_str(), buffptrs) ==
+                FAIL) {
                 raiseException(STATUS_RETURN_FAIL);
             }
         }
@@ -301,8 +304,7 @@ private:
         /// \param dest The destination matrix (every record is a vector)
         /// \param field The specific field name
         /// \param records The number of records to be read
-        template <class T>
-        void read(std::vector<std::vector<T> >& dest, const std::string& field, int32 records) {
+        template <class T> void read(std::vector<std::vector<T>> &dest, const std::string &field, int32 records) {
             if (!records) {
                 records = nrRecords;
             }
@@ -311,7 +313,7 @@ private:
                 raiseException(STATUS_RETURN_FAIL);
             }
 
-            int32 fieldSize = VSsizeof(id, (char*)field.c_str());
+            int32 fieldSize = VSsizeof(id, (char *)field.c_str());
             if (fieldSize % sizeof(T) != 0) {
                 raiseException(BUFFER_SIZE_NOT_DIVISIBLE);
             }
@@ -340,7 +342,7 @@ private:
             }
         }
 
-    private:
+      private:
         intn _size;
         std::string name;
 
@@ -361,20 +363,26 @@ private:
     int32 vId;
 };
 
-/// HdfItem iterator, gives the possibility to iterate over the items from the item
+/// HdfItem iterator, gives the possibility to iterate over the items from the
+/// item
 class HdfItem::Iterator : public HdfObject, public std::iterator<std::bidirectional_iterator_tag, HdfItem> {
-public:
-    Iterator(int32 sId, int32 vId, int32 key, int32 index, Type type, const HdfDestroyerChain& chain) :
-            HdfObject(type, ITERATOR, chain),
-            sId(sId),
-            vId(vId),
-            key(key),
-            index(index) {}
-
-    bool operator!=(const Iterator& it) { return index != it.index; }
-    bool operator==(const Iterator& it) { return index == it.index; }
-
-    Iterator& operator++() {
+  public:
+    Iterator(int32 sId, int32 vId, int32 key, int32 index, Type type, const HdfDestroyerChain &chain)
+        : HdfObject(type, ITERATOR, chain)
+        , sId(sId)
+        , vId(vId)
+        , key(key)
+        , index(index) {
+    }
+
+    bool operator!=(const Iterator &it) {
+        return index != it.index;
+    }
+    bool operator==(const Iterator &it) {
+        return index == it.index;
+    }
+
+    Iterator &operator++() {
         ++index;
         return *this;
     }
@@ -383,7 +391,7 @@ public:
         ++index;
         return it;
     }
-    Iterator& operator--() {
+    Iterator &operator--() {
         --index;
         return *this;
     }
@@ -395,13 +403,13 @@ public:
 
     HdfItem operator*() {
         int32 tag, ref;
-        if(Vgettagref(key, index, &tag, &ref) == FAIL) {
+        if (Vgettagref(key, index, &tag, &ref) == FAIL) {
             raiseException(OUT_OF_RANGE);
         }
-        if(Visvs(key, ref)) {
+        if (Visvs(key, ref)) {
             int32 id = VSattach(vId, ref, "r");
             return HdfItem(new HdfDataItem(id, chain), sId, vId);
-        } else if(Visvg(key, ref)) {
+        } else if (Visvg(key, ref)) {
             int32 id = Vattach(vId, ref, "r");
             return HdfItem(new HdfGroupItem(id, chain), sId, vId);
         } else {
@@ -410,7 +418,7 @@ public:
         }
     }
 
-private:
+  private:
     int32 sId;
     int32 vId;
     int32 key;
@@ -419,4 +427,4 @@ private:
 };
 }
 
-#endif //HDF4CPP_HDFITEM_H
+#endif // HDF4CPP_HDFITEM_H

+ 41 - 19
include/hdf4cpp/HdfObject.h

@@ -1,15 +1,16 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #ifndef HDF4CPP_HDFOBJECT_H
 #define HDF4CPP_HDFOBJECT_H
 
 #include <hdf4cpp/HdfDefines.h>
 #include <hdf4cpp/HdfException.h>
 
-#include <vector>
 #include <functional>
 #include <memory>
+#include <vector>
 
 namespace hdf4cpp {
 
@@ -19,12 +20,16 @@ class HdfObject {
     /// This class is responsible to call the end access functions
     class HdfDestroyer {
       public:
-        HdfDestroyer(const std::function<int32 (int32)>& endFunction, int32 id) : endFunction(endFunction), id(id) {}
+        HdfDestroyer(const std::function<int32(int32)> &endFunction, int32 id)
+            : endFunction(endFunction)
+            , id(id) {
+        }
         ~HdfDestroyer() {
             endFunction(id);
         }
-    private:
-        std::function<int32 (int32)> endFunction;
+
+      private:
+        std::function<int32(int32)> endFunction;
         int32 id;
     };
     /// A chain of destroyers.
@@ -33,40 +38,57 @@ class HdfObject {
     /// then the destructor of the destroyer will call the end access function.
     class HdfDestroyerChain {
       public:
-        HdfDestroyerChain() {}
-        HdfDestroyerChain(const HdfDestroyerChain& other) : chain(other.chain) {}
+        HdfDestroyerChain() {
+        }
+        HdfDestroyerChain(const HdfDestroyerChain &other)
+            : chain(other.chain) {
+        }
 
-        void pushBack(HdfDestroyer * destroyer) {
+        void pushBack(HdfDestroyer *destroyer) {
             chain.push_back(std::shared_ptr<HdfDestroyer>(destroyer));
         }
 
       private:
-        std::vector<std::shared_ptr<HdfDestroyer> > chain;
+        std::vector<std::shared_ptr<HdfDestroyer>> chain;
     };
 
   public:
     /// \returns the type of the object
-    virtual Type getType() const { return type; }
+    virtual Type getType() const {
+        return type;
+    }
 
     /// \returns the class type of the object
-    virtual ClassType getClassType() const { return classType; }
+    virtual ClassType getClassType() const {
+        return classType;
+    }
 
   protected:
-    HdfObject(const Type& type, const ClassType& classType, const HdfDestroyerChain& chain = HdfDestroyerChain()) : type(type),
-                                                                                                                    classType(classType),
-                                                                                                                    chain(chain) {}
-    HdfObject(const HdfObject *object) : type(object->getType()), classType(object->getClassType()), chain(object->chain) {}
+    HdfObject(const Type &type, const ClassType &classType, const HdfDestroyerChain &chain = HdfDestroyerChain())
+        : type(type)
+        , classType(classType)
+        , chain(chain) {
+    }
+    HdfObject(const HdfObject *object)
+        : type(object->getType())
+        , classType(object->getClassType())
+        , chain(object->chain) {
+    }
 
-    virtual void setType(const Type& type) { this->type = type; }
-    virtual void setClassType(const ClassType& classType) { this->classType = classType; }
+    virtual void setType(const Type &type) {
+        this->type = type;
+    }
+    virtual void setClassType(const ClassType &classType) {
+        this->classType = classType;
+    }
 
     /// Throws an HdfException by its type
-    virtual void raiseException(const ExceptionType& exceptionType) const {
+    virtual void raiseException(const ExceptionType &exceptionType) const {
         throw HdfException(type, classType, exceptionType);
     }
 
     /// Thorws an HdfException by its message, the type will be OTHER.
-    virtual void raiseException(const std::string& message) const {
+    virtual void raiseException(const std::string &message) const {
         throw HdfException(type, classType, message);
     }
 
@@ -82,4 +104,4 @@ class HdfObject {
 };
 }
 
-#endif //HDF4CPP_HDFOBJECT_H
+#endif // HDF4CPP_HDFOBJECT_H

+ 30 - 17
lib/HdfAttribute.cpp

@@ -1,15 +1,19 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
-#include <hdf4cpp/HdfDefines.h>
+
 #include <hdf4cpp/HdfAttribute_priv.h>
+#include <hdf4cpp/HdfDefines.h>
 #include <stdexcept>
 
 using namespace hdf4cpp;
 
-hdf4cpp::HdfAttribute::HdfDatasetAttribute::HdfDatasetAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, SDfindattr(id, name.c_str()), SDATA, chain) {
+hdf4cpp::HdfAttribute::HdfDatasetAttribute::HdfDatasetAttribute(int32 id,
+                                                                const std::string &name,
+                                                                const HdfDestroyerChain &chain)
+    : HdfAttributeBase(id, SDfindattr(id, name.c_str()), SDATA, chain) {
     char waste[MAX_NAME_LENGTH];
-    if(SDattrinfo(id, index, waste, &dataType, &_size) == FAIL) {
+    if (SDattrinfo(id, index, waste, &dataType, &_size) == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 }
@@ -23,22 +27,25 @@ void hdf4cpp::HdfAttribute::HdfDatasetAttribute::get(void *dest) {
     int32 nrValues;
     char nameRet[MAX_NAME_LENGTH];
     int32 status = SDattrinfo(id, index, nameRet, &dataType, &nrValues);
-    if(status == FAIL) {
+    if (status == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 
-    if(SDreadattr(id, index, dest) == FAIL) {
+    if (SDreadattr(id, index, dest) == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 }
-hdf4cpp::HdfAttribute::HdfGroupAttribute::HdfGroupAttribute(int32 id, const std::string& name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, 0, VGROUP, chain) {
+hdf4cpp::HdfAttribute::HdfGroupAttribute::HdfGroupAttribute(int32 id,
+                                                            const std::string &name,
+                                                            const HdfDestroyerChain &chain)
+    : HdfAttributeBase(id, 0, VGROUP, chain) {
     int32 nrAtts = Vnattrs2(id);
-    for(intn i = 0; i < nrAtts; ++i) {
+    for (intn i = 0; i < nrAtts; ++i) {
         char names[MAX_NAME_LENGTH];
         int32 type, count, size, nFields;
         uint16 refNum;
         Vattrinfo2(id, i, names, &type, &count, &size, &nFields, &refNum);
-        if(name == std::string(names)) {
+        if (name == std::string(names)) {
             index = i;
             _size = count;
             dataType = type;
@@ -54,12 +61,15 @@ int32 hdf4cpp::HdfAttribute::HdfGroupAttribute::getDataType() const {
     return dataType;
 }
 void hdf4cpp::HdfAttribute::HdfGroupAttribute::get(void *dest) {
-    if(Vgetattr2(id, index, dest) == FAIL) {
+    if (Vgetattr2(id, index, dest) == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 }
-hdf4cpp::HdfAttribute::HdfDataAttribute::HdfDataAttribute(int32 id, const std::string &name, const HdfDestroyerChain& chain) : HdfAttributeBase(id, VSfindattr(id, _HDF_VDATA, name.c_str()), VDATA, chain) {
-    if(VSattrinfo(id, _HDF_VDATA, index, nullptr, &dataType, &_size, nullptr) == FAIL) {
+hdf4cpp::HdfAttribute::HdfDataAttribute::HdfDataAttribute(int32 id,
+                                                          const std::string &name,
+                                                          const HdfDestroyerChain &chain)
+    : HdfAttributeBase(id, VSfindattr(id, _HDF_VDATA, name.c_str()), VDATA, chain) {
+    if (VSattrinfo(id, _HDF_VDATA, index, nullptr, &dataType, &_size, nullptr) == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 }
@@ -67,16 +77,18 @@ intn hdf4cpp::HdfAttribute::HdfDataAttribute::size() const {
     return _size;
 }
 void hdf4cpp::HdfAttribute::HdfDataAttribute::get(void *dest) {
-    if(VSgetattr(id, _HDF_VDATA, index, dest) == FAIL) {
+    if (VSgetattr(id, _HDF_VDATA, index, dest) == FAIL) {
         raiseException(STATUS_RETURN_FAIL);
     }
 }
 int32 hdf4cpp::HdfAttribute::HdfDataAttribute::getDataType() const {
     return dataType;
 }
-hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other) : HdfObject(other.getType(), other.getClassType(), std::move(other.chain)), attribute(std::move(other.attribute)) {
+hdf4cpp::HdfAttribute::HdfAttribute(HdfAttribute &&other)
+    : HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
+    , attribute(std::move(other.attribute)) {
 }
-hdf4cpp::HdfAttribute& hdf4cpp::HdfAttribute::operator=(HdfAttribute&& attr) {
+hdf4cpp::HdfAttribute &hdf4cpp::HdfAttribute::operator=(HdfAttribute &&attr) {
     attribute = std::move(attr.attribute);
     setType(attribute->getType());
     setClassType(attribute->getClassType());
@@ -85,12 +97,13 @@ hdf4cpp::HdfAttribute& hdf4cpp::HdfAttribute::operator=(HdfAttribute&& attr) {
 intn hdf4cpp::HdfAttribute::size() const {
     return attribute->size();
 }
-HdfAttribute::HdfAttribute(HdfAttributeBase* attribute)  : HdfObject(attribute), attribute(attribute) {
-
+HdfAttribute::HdfAttribute(HdfAttributeBase *attribute)
+    : HdfObject(attribute)
+    , attribute(attribute) {
 }
 int32 HdfAttribute::getDataType() const {
     return attribute->getDataType();
 }
-void HdfAttribute::getInternal(void* dest) {
+void HdfAttribute::getInternal(void *dest) {
     attribute->get(dest);
 }

+ 15 - 10
lib/HdfException.cpp

@@ -1,22 +1,27 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #include <hdf4cpp/HdfException.h>
 
 
 const std::string hdf4cpp::HdfException::exceptionMessagePrefix = "HDF4CPP: ";
 
 const std::map<hdf4cpp::ExceptionType, std::string> hdf4cpp::HdfException::exceptionTypeMap = {
-        {INVALID_ID, "cannot construct object, the id is invalid"},
-        {INVALID_OPERATION, "operation not supported for this type"},
-        {INVALID_NAME, "invalid item name"},
-        {OUT_OF_RANGE, "out of range, cannot access element (usually thrown when an iterator points to an inaccessible address)"},
-        {BUFFER_SIZE_NOT_ENOUGH, "not enough buffer size (usually thrown when the type of the vector in which we read the data is too small)"},
-        {BUFFER_SIZE_NOT_DIVISIBLE, "buffer cannot be splited up (usually thrown when the size of the readable data is not divisible by the type size of the vector"},
-        {INVALID_RANGES, "the given ranges are invalids (usually thrown when the ranges is negative or it is bigger than the dimension of tha data)"},
-        {STATUS_RETURN_FAIL, "hdf routine failed"},
-        {INVALID_DATA_TYPE, "the type of the data in the hdf item is not supported"},
-        {OTHER, "exception thrown"},
+{INVALID_ID, "cannot construct object, the id is invalid"},
+{INVALID_OPERATION, "operation not supported for this type"},
+{INVALID_NAME, "invalid item name"},
+{OUT_OF_RANGE,
+ "out of range, cannot access element (usually thrown when an iterator points to an inaccessible address)"},
+{BUFFER_SIZE_NOT_ENOUGH,
+ "not enough buffer size (usually thrown when the type of the vector in which we read the data is too small)"},
+{BUFFER_SIZE_NOT_DIVISIBLE, "buffer cannot be splited up (usually thrown when the size of the readable data is not "
+                            "divisible by the type size of the vector"},
+{INVALID_RANGES, "the given ranges are invalids (usually thrown when the ranges is negative or it is bigger than the "
+                 "dimension of tha data)"},
+{STATUS_RETURN_FAIL, "hdf routine failed"},
+{INVALID_DATA_TYPE, "the type of the data in the hdf item is not supported"},
+{OTHER, "exception thrown"},
 };
 
 hdf4cpp::Type hdf4cpp::HdfException::getType() const noexcept {

+ 37 - 36
lib/HdfFile.cpp

@@ -1,52 +1,55 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #include <hdf/mfhdf.h>
 #include <stdexcept>
 
+#include <hdf4cpp/HdfAttribute_priv.h>
 #include <hdf4cpp/HdfDefines.h>
+#include <hdf4cpp/HdfException.h>
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
-#include <hdf4cpp/HdfAttribute_priv.h>
-#include <hdf4cpp/HdfException.h>
 
 
-hdf4cpp::HdfFile::HdfFile(const std::string& path) : HdfObject(HFILE, FILE) {
+hdf4cpp::HdfFile::HdfFile(const std::string &path)
+    : HdfObject(HFILE, FILE) {
     sId = SDstart(path.c_str(), DFACC_READ);
     vId = Hopen(path.c_str(), DFACC_READ, 0);
 
-    if(sId == FAIL || vId == FAIL) {
+    if (sId == FAIL || vId == FAIL) {
         raiseException(INVALID_ID);
     }
 
-    Vstart(vId);
+    Vinitialize(vId);
 
     chain.pushBack(new HdfDestroyer(&SDend, sId));
     chain.pushBack(new HdfDestroyer(&Vfinish, vId));
     chain.pushBack(new HdfDestroyer(&Hclose, vId));
 
     int32 loneSize = Vlone(vId, nullptr, 0);
-    std::vector<int32> refs((size_t) loneSize);
+    std::vector<int32> refs((size_t)loneSize);
     Vlone(vId, refs.data(), loneSize);
-    for(const auto& ref : refs) {
+    for (const auto &ref : refs) {
         loneRefs.push_back(std::pair<int32, Type>(ref, VGROUP));
     }
 
     int32 loneVdata = VSlone(vId, nullptr, 0);
-    refs.resize((size_t) loneVdata);
+    refs.resize((size_t)loneVdata);
     VSlone(vId, refs.data(), loneVdata);
-    for(const auto& ref : refs) {
+    for (const auto &ref : refs) {
         loneRefs.push_back(std::pair<int32, Type>(ref, VDATA));
     }
 }
-hdf4cpp::HdfFile::HdfFile(HdfFile&& file) : HdfObject(file.getType(), file.getClassType()) {
+hdf4cpp::HdfFile::HdfFile(HdfFile &&file)
+    : HdfObject(file.getType(), file.getClassType()) {
     sId = file.sId;
     vId = file.vId;
     loneRefs = file.loneRefs;
     file.sId = file.vId = FAIL;
     loneRefs.clear();
 }
-hdf4cpp::HdfFile& hdf4cpp::HdfFile::operator=(HdfFile&& file) {
+hdf4cpp::HdfFile &hdf4cpp::HdfFile::operator=(HdfFile &&file) {
     setType(file.getType());
     setClassType(file.getClassType());
     sId = file.sId;
@@ -76,13 +79,13 @@ int32 hdf4cpp::HdfFile::getDataId(const std::string &name) const {
     int32 ref = VSfind(vId, name.c_str());
     return (!ref) ? (FAIL) : (VSattach(vId, ref, "r"));
 }
-hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string& name) const {
+hdf4cpp::HdfItem hdf4cpp::HdfFile::get(const std::string &name) const {
     int32 id = getDatasetId(name);
-    if(id == FAIL) {
+    if (id == FAIL) {
         id = getGroupId(name);
-        if(id == FAIL) {
+        if (id == FAIL) {
             id = getDataId(name);
-            if(id == FAIL) {
+            if (id == FAIL) {
                 raiseException(INVALID_ID);
             }
             return HdfItem(new HdfItem::HdfDataItem(id, chain), sId, vId);
@@ -96,10 +99,10 @@ std::vector<int32> hdf4cpp::HdfFile::getDatasetIds(const std::string &name) cons
     char nameDataset[MAX_NAME_LENGTH];
     int32 datasets, waste;
     SDfileinfo(sId, &datasets, &waste);
-    for(int32 i = 0; i < datasets; ++i) {
+    for (int32 i = 0; i < datasets; ++i) {
         int32 id = SDselect(sId, i);
         SDgetinfo(id, nameDataset, nullptr, nullptr, nullptr, nullptr);
-        if(id != FAIL && name == std::string(nameDataset)) {
+        if (id != FAIL && name == std::string(nameDataset)) {
             ids.push_back(id);
         } else {
             SDendaccess(id);
@@ -111,10 +114,10 @@ std::vector<int32> hdf4cpp::HdfFile::getGroupDataIds(const std::string &name) co
     std::vector<int32> ids;
     char nameGroup[MAX_NAME_LENGTH];
     int32 ref = Vgetid(vId, -1);
-    while(ref != FAIL) {
+    while (ref != FAIL) {
         int32 id = Vattach(vId, ref, "r");
         Vgetname(id, nameGroup);
-        if(name == std::string(nameGroup)) {
+        if (name == std::string(nameGroup)) {
             ids.push_back(id);
         } else {
             Vdetach(id);
@@ -123,15 +126,15 @@ std::vector<int32> hdf4cpp::HdfFile::getGroupDataIds(const std::string &name) co
     }
     return ids;
 }
-std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string& name) const {
+std::vector<hdf4cpp::HdfItem> hdf4cpp::HdfFile::getAll(const std::string &name) const {
     std::vector<HdfItem> items;
     std::vector<int32> ids;
     ids = getDatasetIds(name);
-    for(const auto& id : ids) {
+    for (const auto &id : ids) {
         items.push_back(HdfItem(new HdfItem::HdfDatasetItem(id, chain), sId, vId));
     }
     ids = getGroupDataIds(name);
-    for(const auto& id : ids) {
+    for (const auto &id : ids) {
         items.push_back(HdfItem(new HdfItem::HdfGroupItem(id, chain), sId, vId));
     }
     return std::move(items);
@@ -143,24 +146,22 @@ hdf4cpp::HdfFile::Iterator hdf4cpp::HdfFile::begin() const {
     return Iterator(this, 0, chain);
 }
 hdf4cpp::HdfFile::Iterator hdf4cpp::HdfFile::end() const {
-    return Iterator(this, (int32) loneRefs.size(), chain);
+    return Iterator(this, (int32)loneRefs.size(), chain);
 }
 hdf4cpp::HdfItem hdf4cpp::HdfFile::Iterator::operator*() {
-    if(index < 0 || index >= (int) file->loneRefs.size()) {
+    if (index < 0 || index >= (int)file->loneRefs.size()) {
         raiseException(OUT_OF_RANGE);
     }
     int32 ref = file->loneRefs[index].first;
-    switch(file->loneRefs[index].second) {
-        case VGROUP: {
-            int32 id = Vattach(file->vId, ref, "r");
-            return HdfItem(new HdfItem::HdfGroupItem(id, chain), file->sId, file->vId);
-        }
-        case VDATA: {
-            int32 id = VSattach(file->vId, ref, "r");
-            return HdfItem(new HdfItem::HdfDataItem(id, chain), file->sId, file->vId);
-        }
-        default: {
-            raiseException(INVALID_OPERATION);
-        }
+    switch (file->loneRefs[index].second) {
+    case VGROUP: {
+        int32 id = Vattach(file->vId, ref, "r");
+        return HdfItem(new HdfItem::HdfGroupItem(id, chain), file->sId, file->vId);
+    }
+    case VDATA: {
+        int32 id = VSattach(file->vId, ref, "r");
+        return HdfItem(new HdfItem::HdfDataItem(id, chain), file->sId, file->vId);
+    }
+    default: { raiseException(INVALID_OPERATION); }
     }
 }

+ 29 - 25
lib/HdfItem.cpp

@@ -1,17 +1,17 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
+#include <hdf/mfhdf.h>
+#include <hdf4cpp/HdfAttribute_priv.h>
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
-#include <hdf4cpp/HdfAttribute_priv.h>
-#include <hdf/mfhdf.h>
 #include <sstream>
 
-hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, SDATA, chain) {
+hdf4cpp::HdfItem::HdfDatasetItem::HdfDatasetItem(int32 id, const HdfDestroyerChain &chain)
+    : HdfItemBase(id, SDATA, chain) {
     _size = 1;
-    std::for_each(dims.begin(), dims.end(), [this](const int32 &t) {
-        _size *= t;
-    });
+    std::for_each(dims.begin(), dims.end(), [this](const int32 &t) { _size *= t; });
     int32 dim[MAX_DIMENSION];
     int32 size;
     char _name[MAX_NAME_LENGTH];
@@ -40,7 +40,8 @@ hdf4cpp::HdfItem::HdfDatasetItem::~HdfDatasetItem() {
 intn hdf4cpp::HdfItem::HdfDatasetItem::size() const {
     return _size;
 }
-hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, VGROUP, chain) {
+hdf4cpp::HdfItem::HdfGroupItem::HdfGroupItem(int32 id, const HdfDestroyerChain &chain)
+    : HdfItemBase(id, VGROUP, chain) {
     char _name[MAX_NAME_LENGTH];
     Vgetname(id, _name);
     name = std::string(_name);
@@ -66,7 +67,8 @@ intn hdf4cpp::HdfItem::HdfGroupItem::size() const {
 int32 hdf4cpp::HdfItem::HdfGroupItem::getDataType() const {
     raiseException(INVALID_OPERATION);
 }
-hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain& chain) : HdfItemBase(id, VDATA, chain) {
+hdf4cpp::HdfItem::HdfDataItem::HdfDataItem(int32 id, const HdfDestroyerChain &chain)
+    : HdfItemBase(id, VDATA, chain) {
     this->chain.pushBack(new HdfDestroyer(&VSdetach, id));
     char _name[MAX_NAME_LENGTH];
     VSinquire(id, &nrRecords, &interlace, nullptr, &recordSize, _name);
@@ -92,15 +94,19 @@ intn hdf4cpp::HdfItem::HdfDataItem::size() const {
 int32 hdf4cpp::HdfItem::HdfDataItem::getDataType() const {
     return 0;
 }
-hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId) : HdfObject(item),
-                                                                     item(item),
-                                                                     sId(sId),
-                                                                     vId(vId) {}
-hdf4cpp::HdfItem::HdfItem(HdfItem&& other) : HdfObject(other.getType(), other.getClassType(), std::move(other.chain)),
-                                             item(std::move(other.item)),
-                                             sId(other.sId),
-                                             vId(other.vId) {}
-hdf4cpp::HdfItem& hdf4cpp::HdfItem::operator=(HdfItem&& it) {
+hdf4cpp::HdfItem::HdfItem(HdfItemBase *item, int32 sId, int32 vId)
+    : HdfObject(item)
+    , item(item)
+    , sId(sId)
+    , vId(vId) {
+}
+hdf4cpp::HdfItem::HdfItem(HdfItem &&other)
+    : HdfObject(other.getType(), other.getClassType(), std::move(other.chain))
+    , item(std::move(other.item))
+    , sId(other.sId)
+    , vId(other.vId) {
+}
+hdf4cpp::HdfItem &hdf4cpp::HdfItem::operator=(HdfItem &&it) {
     item = std::move(it.item);
     return *this;
 }
@@ -120,13 +126,11 @@ hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::begin() const {
     return Iterator(sId, vId, item->getId(), 0, getType(), chain);
 }
 hdf4cpp::HdfItem::Iterator hdf4cpp::HdfItem::end() const {
-    switch(item->getType()) {
-        case VGROUP: {
-            int32 size = Vntagrefs(item->getId());
-            return Iterator(sId, vId, item->getId(), size, getType(), chain);
-        }
-        default: {
-            return Iterator(sId, vId, item->getId(), 0, getType(), chain);
-        }
+    switch (item->getType()) {
+    case VGROUP: {
+        int32 size = Vntagrefs(item->getId());
+        return Iterator(sId, vId, item->getId(), size, getType(), chain);
+    }
+    default: { return Iterator(sId, vId, item->getId(), 0, getType(), chain); }
     }
 }

+ 13 - 9
tests/HdfFileTest.cpp

@@ -1,16 +1,19 @@
 /// \copyright Copyright (c) Catalysts GmbH
 /// \author Patrik Kovacs, Catalysts GmbH
 
+
 #include <gtest/gtest.h>
+#include <hdf4cpp/HdfAttribute_priv.h>
 #include <hdf4cpp/HdfFile.h>
 #include <hdf4cpp/HdfItem.h>
-#include <hdf4cpp/HdfAttribute_priv.h>
 
 using namespace hdf4cpp;
 
 class HdfFileTest : public ::testing::Test {
   protected:
-    HdfFileTest() : file(std::string(TEST_DATA_PATH) + "small_test.hdf") {}
+    HdfFileTest()
+        : file(std::string(TEST_DATA_PATH) + "small_test.hdf") {
+    }
 
     HdfFile file;
 };
@@ -148,16 +151,17 @@ TEST_F(HdfFileTest, GlobalAttribute) {
 
 TEST_F(HdfFileTest, FileIterator) {
     std::ostringstream out;
-    for(auto it : file) {
+    for (auto it : file) {
         out << it.getName() << '*';
     }
-    ASSERT_EQ(out.str(), std::string("Group*GroupWithOnlyAttribute*RIG0.0*/home/patrik/HDF4CPP/tests/test_data/small_test.hdf*Egy*One*Ein*Vdata*attribute*"));
+    ASSERT_EQ(out.str(), std::string("Group*GroupWithOnlyAttribute*RIG0.0*/home/patrik/HDF4CPP/tests/test_data/"
+                                     "small_test.hdf*Egy*One*Ein*Vdata*attribute*"));
 }
 
 TEST_F(HdfFileTest, GroupIterator) {
     HdfItem item = file.get("Group");
     std::ostringstream out;
-    for(auto it : item) {
+    for (auto it : item) {
         out << it.getName() << '*';
     }
     ASSERT_EQ(out.str(), "Data*DataWithAttributes*");
@@ -166,11 +170,11 @@ TEST_F(HdfFileTest, GroupIterator) {
 TEST_F(HdfFileTest, IteratingOverNonGroupItems) {
     std::ostringstream out;
     HdfItem sdata = file.get("DoubleDataset");
-    for(const auto& item : sdata) {
+    for (const auto &item : sdata) {
         out << item.getName();
     }
     HdfItem vdata = file.get("Vdata");
-    for(const auto& item : vdata) {
+    for (const auto &item : vdata) {
         out << item.getName();
     }
     ASSERT_TRUE(out.str().empty());
@@ -197,11 +201,11 @@ TEST_F(HdfFileTest, VDataRead1) {
 TEST_F(HdfFileTest, VDataRead2) {
     HdfItem item = file.get("Vdata");
     ASSERT_EQ(item.getName(), "Vdata");
-    std::vector<std::vector<char> > vec;
+    std::vector<std::vector<char>> vec;
     item.read(vec, "name");
     std::vector<std::string> exp = {"Patrick Jane", "Barry Allen", "Angus MacGyver"};
     ASSERT_EQ(vec.size(), 3);
-    for(int i = 0; i < 3; ++i) {
+    for (int i = 0; i < 3; ++i) {
         ASSERT_EQ(std::string(vec[i].data()), exp[i]);
     }
 }