Apply clang-format to source tree
[alexxy/gromacs.git] / src / gromacs / selection / sm_merge.cpp
index 048e5ca3e4270a1497cedacbff05dd132a2801ac..553c10fc543eaf2f59444aa01f8315003255cacb 100644 (file)
 typedef struct
 {
     /** Input positions. */
-    gmx_ana_pos_t    p1;
+    gmx_ana_pos_t p1;
     /** Other input positions. */
-    gmx_ana_pos_t    p2;
+    gmx_ana_pos_t p2;
     /** Stride for merging (\c stride values from \c p1 for each in \c p2). */
-    int              stride;
+    int stride;
 } t_methoddata_merge;
 
 /** Allocates data for the merging selection modifiers. */
-static void *
-init_data_merge(int npar, gmx_ana_selparam_t *param);
+static void* init_data_merge(int npar, gmx_ana_selparam_t* param);
 /*! \brief
  * Initializes data for the merging selection modifiers.
  *
@@ -76,17 +75,13 @@ init_data_merge(int npar, gmx_ana_selparam_t *param);
  * \param[in] data  Should point to a \p t_methoddata_merge.
  * \returns   0 if everything is successful, -1 on error.
  */
-static void
-init_merge(const gmx_mtop_t *top, int npar, gmx_ana_selparam_t *param, void *data);
+static void init_merge(const gmx_mtop_t* top, int npar, gmx_ana_selparam_t* param, void* data);
 /** Initializes output for the \p merge selection modifier. */
-static void
-init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
+static void init_output_merge(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data);
 /** Initializes output for the \p plus selection modifier. */
-static void
-init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data);
+static void init_output_plus(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data);
 /** Frees the memory allocated for the merging selection modifiers. */
-static void
-free_data_merge(void *data);
+static void free_data_merge(void* data);
 /*! \brief
  * Evaluates the \p merge selection modifier.
  *
@@ -95,9 +90,10 @@ free_data_merge(void *data);
  * \param[out] out   Output data structure (\p out->u.p is used).
  * \param[in]  data  Should point to a \p t_methoddata_merge.
  */
-static void
-evaluate_merge(const gmx::SelMethodEvalContext &context,
-               gmx_ana_pos_t * p, gmx_ana_selvalue_t *out, void *data);
+static void evaluate_merge(const gmx::SelMethodEvalContext& context,
+                           gmx_ana_pos_t*                   p,
+                           gmx_ana_selvalue_t*              out,
+                           void*                            data);
 /*! \brief
  * Evaluates the \p plus selection modifier.
  *
@@ -106,21 +102,22 @@ evaluate_merge(const gmx::SelMethodEvalContext &context,
  * \param[out] out   Output data structure (\p out->u.p is used).
  * \param[in]  data  Should point to a \p t_methoddata_merge.
  */
-static void
-evaluate_plus(const gmx::SelMethodEvalContext &context,
-              gmx_ana_pos_t * p, gmx_ana_selvalue_t *out, void *data);
+static void evaluate_plus(const gmx::SelMethodEvalContext& context,
+                          gmx_ana_pos_t*                   p,
+                          gmx_ana_selvalue_t*              out,
+                          void*                            data);
 
 /** Parameters for the merging selection modifiers. */
 static gmx_ana_selparam_t smparams_merge[] = {
-    {nullptr,       {POS_VALUE, -1, {nullptr}}, nullptr, SPAR_DYNAMIC | SPAR_VARNUM},
-    {nullptr,       {POS_VALUE, -1, {nullptr}}, nullptr, SPAR_DYNAMIC | SPAR_VARNUM},
-    {"stride",   {INT_VALUE,  1, {nullptr}}, nullptr, SPAR_OPTIONAL},
+    { nullptr, { POS_VALUE, -1, { nullptr } }, nullptr, SPAR_DYNAMIC | SPAR_VARNUM },
+    { nullptr, { POS_VALUE, -1, { nullptr } }, nullptr, SPAR_DYNAMIC | SPAR_VARNUM },
+    { "stride", { INT_VALUE, 1, { nullptr } }, nullptr, SPAR_OPTIONAL },
 };
 
 //! Help title for the merging selection modifiers.
-static const char        helptitle_merge[] = "Merging selections";
+static const char helptitle_merge[] = "Merging selections";
 //! Help text for the merging selection modifiers.
-static const char *const help_merge[] = {
+static const charconst help_merge[] = {
     "::",
     "",
     "  POSEXPR merge POSEXPR [stride INT]",
@@ -147,8 +144,11 @@ static const char *const help_merge[] = {
 
 /** Selection method data for the \p plus modifier. */
 gmx_ana_selmethod_t sm_merge = {
-    "merge", POS_VALUE, SMETH_MODIFIER,
-    asize(smparams_merge), smparams_merge,
+    "merge",
+    POS_VALUE,
+    SMETH_MODIFIER,
+    asize(smparams_merge),
+    smparams_merge,
     &init_data_merge,
     nullptr,
     &init_merge,
@@ -157,13 +157,16 @@ gmx_ana_selmethod_t sm_merge = {
     nullptr,
     nullptr,
     &evaluate_merge,
-    {"merge POSEXPR", helptitle_merge, asize(help_merge), help_merge},
+    { "merge POSEXPR", helptitle_merge, asize(help_merge), help_merge },
 };
 
 /** Selection method data for the \p plus modifier. */
 gmx_ana_selmethod_t sm_plus = {
-    "plus", POS_VALUE, SMETH_MODIFIER,
-    asize(smparams_merge)-1, smparams_merge,
+    "plus",
+    POS_VALUE,
+    SMETH_MODIFIER,
+    asize(smparams_merge) - 1,
+    smparams_merge,
     &init_data_merge,
     nullptr,
     &init_merge,
@@ -172,7 +175,7 @@ gmx_ana_selmethod_t sm_plus = {
     nullptr,
     nullptr,
     &evaluate_plus,
-    {"plus POSEXPR", helptitle_merge, asize(help_merge), help_merge},
+    { "plus POSEXPR", helptitle_merge, asize(help_merge), help_merge },
 };
 
 /*!
@@ -183,13 +186,12 @@ gmx_ana_selmethod_t sm_plus = {
  *
  * Allocates memory for a \p t_methoddata_merge structure.
  */
-static void *
-init_data_merge(int npar, gmx_ana_selparam_t *param)
+static void* init_data_merge(int npar, gmx_ana_selparam_t* param)
 {
-    t_methoddata_merge *data = new t_methoddata_merge();
-    data->stride     = 0;
-    param[0].val.u.p = &data->p1;
-    param[1].val.u.p = &data->p2;
+    t_methoddata_mergedata = new t_methoddata_merge();
+    data->stride             = 0;
+    param[0].val.u.p         = &data->p1;
+    param[1].val.u.p         = &data->p2;
     if (npar > 2)
     {
         param[2].val.u.i = &data->stride;
@@ -197,10 +199,9 @@ init_data_merge(int npar, gmx_ana_selparam_t *param)
     return data;
 }
 
-static void
-init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /* param */, void *data)
+static void init_merge(const gmx_mtop_t* /* top */, int /* npar */, gmx_ana_selparam_t* /* param */, void* data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
 
     if (d->stride < 0)
     {
@@ -211,9 +212,10 @@ init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /*
     {
         d->stride = d->p1.count() / d->p2.count();
     }
-    if (d->p1.count() != d->stride*d->p2.count())
+    if (d->p1.count() != d->stride * d->p2.count())
     {
-        GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
+        GMX_THROW(gmx::InconsistentInputError(
+                "The number of positions to be merged are not compatible"));
     }
 }
 
@@ -224,10 +226,9 @@ init_merge(const gmx_mtop_t * /* top */, int /* npar */, gmx_ana_selparam_t * /*
  * \param[in,out] out   Pointer to output data structure.
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
-static void
-init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
+static void init_output_common(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
 
     GMX_UNUSED_VALUE(top);
     if (d->p1.m.type != d->p2.m.type)
@@ -240,8 +241,7 @@ init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
         out->u.p->m.type = d->p1.m.type;
     }
     gmx_ana_pos_reserve_for_append(out->u.p, d->p1.count() + d->p2.count(),
-                                   d->p1.m.b.nra + d->p2.m.b.nra,
-                                   d->p1.v != nullptr, d->p1.f != nullptr);
+                                   d->p1.m.b.nra + d->p2.m.b.nra, d->p1.v != nullptr, d->p1.f != nullptr);
     gmx_ana_pos_empty_init(out->u.p);
 }
 
@@ -250,10 +250,9 @@ init_output_common(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
  * \param[in,out] out   Pointer to output data structure.
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
-static void
-init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
+static void init_output_merge(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
     int                 i, j;
 
     init_output_common(top, out, data);
@@ -272,10 +271,9 @@ init_output_merge(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
  * \param[in,out] out   Pointer to output data structure.
  * \param[in,out] data  Should point to \c t_methoddata_merge.
  */
-static void
-init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
+static void init_output_plus(const gmx_mtop_t* top, gmx_ana_selvalue_t* out, void* data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
     int                 i;
 
     init_output_common(top, out, data);
@@ -294,48 +292,50 @@ init_output_plus(const gmx_mtop_t *top, gmx_ana_selvalue_t *out, void *data)
  *
  * Frees the memory allocated for \c t_methoddata_merge.
  */
-static void
-free_data_merge(void *data)
+static void free_data_merge(void* data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
     delete d;
 }
 
-static void
-evaluate_merge(const gmx::SelMethodEvalContext & /*context*/,
-               gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data)
+static void evaluate_merge(const gmx::SelMethodEvalContext& /*context*/,
+                           gmx_ana_pos_t* /* p */,
+                           gmx_ana_selvalue_t* out,
+                           void*               data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
     int                 i, j;
     int                 refid;
 
-    if (d->p1.count() != d->stride*d->p2.count())
+    if (d->p1.count() != d->stride * d->p2.count())
     {
-        GMX_THROW(gmx::InconsistentInputError("The number of positions to be merged are not compatible"));
+        GMX_THROW(gmx::InconsistentInputError(
+                "The number of positions to be merged are not compatible"));
     }
     gmx_ana_pos_empty(out->u.p);
     for (i = 0; i < d->p2.count(); ++i)
     {
         for (j = 0; j < d->stride; ++j)
         {
-            refid = d->p1.m.refid[d->stride*i+j];
+            refid = d->p1.m.refid[d->stride * i + j];
             if (refid != -1)
             {
-                refid = (d->stride+1) * (refid / d->stride) + (refid % d->stride);
+                refid = (d->stride + 1) * (refid / d->stride) + (refid % d->stride);
             }
-            gmx_ana_pos_append(out->u.p, &d->p1, d->stride*i+j, refid);
+            gmx_ana_pos_append(out->u.p, &d->p1, d->stride * i + j, refid);
         }
-        refid = (d->stride+1)*d->p2.m.refid[i] + d->stride;
+        refid = (d->stride + 1) * d->p2.m.refid[i] + d->stride;
         gmx_ana_pos_append(out->u.p, &d->p2, i, refid);
     }
     gmx_ana_pos_append_finish(out->u.p);
 }
 
-static void
-evaluate_plus(const gmx::SelMethodEvalContext & /*context*/,
-              gmx_ana_pos_t * /* p */, gmx_ana_selvalue_t *out, void *data)
+static void evaluate_plus(const gmx::SelMethodEvalContext& /*context*/,
+                          gmx_ana_pos_t* /* p */,
+                          gmx_ana_selvalue_t* out,
+                          void*               data)
 {
-    t_methoddata_merge *d = static_cast<t_methoddata_merge *>(data);
+    t_methoddata_merge* d = static_cast<t_methoddata_merge*>(data);
     int                 i;
     int                 refid;