From 25d419ce96b2b0b525a1f46d38f7c714d0a4c018 Mon Sep 17 00:00:00 2001
From: Daniel <d.hornung@indiscale.com>
Date: Thu, 29 Jul 2021 14:50:25 +0200
Subject: [PATCH] ENH: Style test.

---
 .gitlab-ci.yml              |  2 +-
 .miss_hit                   |  2 +-
 Makefile                    | 10 ++++++++--
 src/private/_info.cpp       | 23 +++++++++++------------
 src/private/maoxdbUtils.hpp | 16 ++++++++--------
 5 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 812b8ab..5a99725 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -69,7 +69,7 @@ code_style_cpp:
   tags: [ docker ]
   stage: test
   script:
-    - clang-format-11 --dry-run --verbose --Werror $(find test/ src/ -type f -iname "*.cpp" -o -iname "*.h" -o -iname "*.h.in")
+    - make style
   allow_failure: true
 
 unit_tests:
diff --git a/.miss_hit b/.miss_hit
index f15ccfe..1ec1ed2 100644
--- a/.miss_hit
+++ b/.miss_hit
@@ -2,6 +2,6 @@
 # See https://florianschanda.github.io/miss_hit/style_checker.html
 
 line_length: 100
-regex_function_name: "[a-z]+(_[a-z]+)*"
+regex_function_name: "[_a-z]+(_[a-z]+)*"
 suppress_rule: "whitespace_comments"
 tab_width: 2
diff --git a/Makefile b/Makefile
index e3d9d8d..4c125fb 100644
--- a/Makefile
+++ b/Makefile
@@ -33,9 +33,15 @@ help:
 doc:
 	cd doc && $(MAKE) html
 
-.PHONY: style
 style:
-	mh_style --fix --octave src doc
+	# Wait for https://github.com/florianschanda/miss_hit/issues/224
+	# mh_style --fix --octave src doc
+	clang-format-11 --dry-run --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in")
+.PHONY: style
+
+style_fix:
+	clang-format-11 -i --verbose --Werror $(shell find test/ src/ -type f -iname "*.cpp" -o -iname "*.hpp" -o -iname "*.h" -o -iname "*.h.in")
+.PHONY: style_fix
 
 .PHONY: test
 test:
diff --git a/src/private/_info.cpp b/src/private/_info.cpp
index b3eb701..cdd248f 100644
--- a/src/private/_info.cpp
+++ b/src/private/_info.cpp
@@ -8,16 +8,16 @@
 #include <memory>              // for unique_ptr, __shared_ptr_access, shar...
 #include <string>              // for allocator, char_traits, operator+
 
-using std::string;
 using caosdb::connection::Connection;
 using caosdb::connection::ConnectionManager;
+using std::string;
 
-mxArray* info(const string &connection_name);
+mxArray *info(const string &connection_name);
 
 /**
  * The implementation of the info retrieval.
  */
-mxArray* info(string const &connection_name) {
+mxArray *info(string const &connection_name) {
   std::shared_ptr<Connection> connection = NULL;
   if (connection_name == "") {
     connection = ConnectionManager::GetDefaultConnection();
@@ -27,11 +27,11 @@ mxArray* info(string const &connection_name) {
   const auto &version_info = connection->GetVersionInfo();
   const char *keys[] = {"major", "minor", "patch", "pre_release", "build"};
   mwSize dims[2] = {1, 1};
-  mxArray* info_struct = mxCreateStructArray(2, dims, 5, keys);
+  mxArray *info_struct = mxCreateStructArray(2, dims, 5, keys);
 
-  auto* major = mxSCALAR(UINT64, major, version_info->GetMajor());
-  auto* minor = mxSCALAR(UINT64, minor, version_info->GetMinor());
-  auto* patch = mxSCALAR(UINT64, patch, version_info->GetPatch());
+  auto *major = mxSCALAR(UINT64, major, version_info->GetMajor());
+  auto *minor = mxSCALAR(UINT64, minor, version_info->GetMinor());
+  auto *patch = mxSCALAR(UINT64, patch, version_info->GetPatch());
 
   mxSetField(info_struct, 0, "major", major);
   mxSetField(info_struct, 0, "minor", minor);
@@ -48,19 +48,18 @@ mxArray* info(string const &connection_name) {
  *
  * @details    At the moment, this is just the version of the server.
  *
- * @param connection_name A string with the connection name. May be omitted or an empty string.
+ * @param connection_name A string with the connection name. May be omitted or
+ * an empty string.
  *
  * @return     return type
  */
-void mexFunction(int nlhs, mxArray *plhs[], int nrhs,
-                 const mxArray *prhs[]) {
+void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
 
   string conn_name("");
-  if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0)  {
+  if (nrhs >= 1 && mxGetNumberOfElements(prhs[0]) > 0) {
     conn_name = mxGetChars(prhs[0]);
   }
   mexPrintf("Connection: >%s< \t %d\n", conn_name.c_str(), nrhs);
   auto info_struct = info(conn_name);
   plhs[0] = info_struct;
-
 }
diff --git a/src/private/maoxdbUtils.hpp b/src/private/maoxdbUtils.hpp
index cb40c57..1f68dad 100644
--- a/src/private/maoxdbUtils.hpp
+++ b/src/private/maoxdbUtils.hpp
@@ -5,13 +5,13 @@
 #include "mexproto.h"
 
 /**
- * mxSCALAR(type, name, value): Create a 1x1 mxArray of type TYPE and value VALUE.  The NAME must be
- * unique within each scope.
+ * mxSCALAR(type, name, value): Create a 1x1 mxArray of type TYPE and value
+ * VALUE.  The NAME must be unique within each scope.
  *
  * Use it like so (note that the assignment to NAME is necessary):
  *
  * auto* scalar = mxSCALAR(UINT64, scalar, value);
- * 
+ *
  * This will exand to:
  *
  * mxCreateNumericMatrix(1, 1, mxUINT64_CLASS, mxREAL);
@@ -20,10 +20,10 @@
  * mxSetData(scalar, scalar_data);
  *
  */
-#define mxSCALAR(type, name, value) \
-  mxCreateNumericMatrix(1, 1, mx ## type ## _CLASS, mxREAL);  \
-  auto * __ ## name ##_data = (type ## _T*) mxGetData(name); \
-  __ ## name ## _data[0] = value; \
-  mxSetData(name, __ ## name ## _data)
+#define mxSCALAR(type, name, value)                                            \
+  mxCreateNumericMatrix(1, 1, mx##type##_CLASS, mxREAL);                       \
+  auto *__##name##_data = (type##_T *)mxGetData(name);                         \
+  __##name##_data[0] = value;                                                  \
+  mxSetData(name, __##name##_data)
 
 #endif /* MAOXDBUTILS_H */
-- 
GitLab