Skip to content

Commit

Permalink
Clang-format the project to a more "common" style
Browse files Browse the repository at this point in the history
  • Loading branch information
RickdeJager committed Apr 16, 2021
1 parent 101539b commit f8eb63d
Show file tree
Hide file tree
Showing 189 changed files with 14,303 additions and 14,505 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
BasedOnStyle: llvm
IndentWidth: 4
ColumnLimit: 100
1 change: 1 addition & 0 deletions clang-format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find . -regex '.*\.\(cc\|cpp\|hh\|h\)' -exec clang-format -i {} \;
231 changes: 105 additions & 126 deletions src/AUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,155 +23,134 @@

#include <cmath>
#ifndef log2
// this is in an #ifndef because some cmath implementations #define log2 and some not
# define log2(x) (log(x) / log(2.0))
// this is in an #ifndef because some cmath implementations #define log2 and some not
#define log2(x) (log(x) / log(2.0))
#endif

/**
* \class AUtils
* \brief provides some generic functions for non-standard arithmetic operations
**/
class AUtils {
public:
/**
* return the maximum of a and b (needs >)
**/
template<class T> static T max (T a, T b) ;

/**
* return the minimum of a and b (needs <)
**/
template<class T> static T min (T a, T b) ;

/**
* returns a divided through b rounded up to nearest "integer" (needs =, --, +, /)
**/
template<class T> static T div_roundup (T a, T b) ;

/**
* substraction with the modification to return 0 (T()) for negative difference (needs >, -, T())
**/
template<class T> static T bminus (T a, T b) ;

/**
* addition with the modification to return top for sums that are larger than top
**/
template<class T, T top> static T bplus (T a, T b) ;
template<class T> static T bplus (T a, T b, T top) ;

/**
* calculate the sum s[0]+...s[n-1] modulo m (needs =, +, % for T and =, CTYPE(), <, ++ for CTYPE)
**/
template<class T, class CTYPE> static T modsum (T* s, CTYPE n, T m) ;

/**
* round up x to nearest integer
**/
template<class IT, class FT> static IT roundup (FT x) ;

/**
* compute 2-logarithm of n (rounded up to nearest int), i.e. number of bits needed to store values from {0,...,n-1}
**/
template<class T> static T log2_ceil (T n) ;
} ;

template<class T>
T AUtils::max (T a, T b)
{
if (a > b) {
return a ;
}
else {
return b ;
}
public:
/**
* return the maximum of a and b (needs >)
**/
template <class T> static T max(T a, T b);

/**
* return the minimum of a and b (needs <)
**/
template <class T> static T min(T a, T b);

/**
* returns a divided through b rounded up to nearest "integer" (needs =, --, +, /)
**/
template <class T> static T div_roundup(T a, T b);

/**
* substraction with the modification to return 0 (T()) for negative difference (needs >, -,
*T())
**/
template <class T> static T bminus(T a, T b);

/**
* addition with the modification to return top for sums that are larger than top
**/
template <class T, T top> static T bplus(T a, T b);
template <class T> static T bplus(T a, T b, T top);

/**
* calculate the sum s[0]+...s[n-1] modulo m (needs =, +, % for T and =, CTYPE(), <, ++ for
*CTYPE)
**/
template <class T, class CTYPE> static T modsum(T *s, CTYPE n, T m);

/**
* round up x to nearest integer
**/
template <class IT, class FT> static IT roundup(FT x);

/**
* compute 2-logarithm of n (rounded up to nearest int), i.e. number of bits needed to store
*values from {0,...,n-1}
**/
template <class T> static T log2_ceil(T n);
};

template <class T> T AUtils::max(T a, T b) {
if (a > b) {
return a;
} else {
return b;
}
}

template<class T>
T AUtils::min (T a, T b)
{
if (a < b) {
return a ;
}
else {
return b ;
}
template <class T> T AUtils::min(T a, T b) {
if (a < b) {
return a;
} else {
return b;
}
}

template<class T>
T AUtils::div_roundup (T a, T b)
{
T c = b-- ;
return ((a + b) / c) ;
template <class T> T AUtils::div_roundup(T a, T b) {
T c = b--;
return ((a + b) / c);
}

template<class T>
T AUtils::bminus (T a, T b)
{
if (a > b) {
return (a - b) ;
}
else {
return T() ;
}
template <class T> T AUtils::bminus(T a, T b) {
if (a > b) {
return (a - b);
} else {
return T();
}
}

template<class T, T top>
T AUtils::bplus (T a, T b)
{
a += b ;
if (a > top) {
return top ;
}
else {
return a ;
}
template <class T, T top> T AUtils::bplus(T a, T b) {
a += b;
if (a > top) {
return top;
} else {
return a;
}
}

template<class T>
T AUtils::bplus (T a, T b, T top)
{
a += b ;
if (a > top) {
return top ;
}
else {
return a ;
}
template <class T> T AUtils::bplus(T a, T b, T top) {
a += b;
if (a > top) {
return top;
} else {
return a;
}
}

template<class T, class CTYPE>
T AUtils::modsum (T* s, CTYPE n, T m)
{
T retval = 0 ;
for (CTYPE i = CTYPE() ; i < n ; ++i) {
retval = (retval + s[i]) % m ;
}
return retval ;
template <class T, class CTYPE> T AUtils::modsum(T *s, CTYPE n, T m) {
T retval = 0;
for (CTYPE i = CTYPE(); i < n; ++i) {
retval = (retval + s[i]) % m;
}
return retval;
}

template<class IT, class FT>
IT AUtils::roundup (FT x)
{
IT retval = 0 ;
FT intpart = (FT) ((IT) x) ;
if (x - intpart == (FT) 0.0) {
retval = (IT) x ;
}
else {
retval = ((IT) x) + 1 ;
}
return retval ;
template <class IT, class FT> IT AUtils::roundup(FT x) {
IT retval = 0;
FT intpart = (FT)((IT)x);
if (x - intpart == (FT)0.0) {
retval = (IT)x;
} else {
retval = ((IT)x) + 1;
}
return retval;
}

template<class T>
T AUtils::log2_ceil (T n)
{
T retval = 0 ;
while (n > 1) {
n = div_roundup<T> (n, 2) ;
++retval ;
}
return retval ;
template <class T> T AUtils::log2_ceil(T n) {
T retval = 0;
while (n > 1) {
n = div_roundup<T>(n, 2);
++retval;
}
return retval;
}

#endif // ndef SH_AUTILS_H
18 changes: 8 additions & 10 deletions src/Arg.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@

#include "Arg.h"

template<class T> Arg<T>::Arg (T v, bool setbyuser)
{
set = false ;
setValue (v, setbyuser) ;
template <class T> Arg<T>::Arg(T v, bool setbyuser) {
set = false;
setValue(v, setbyuser);
}

template<class T> void Arg<T>::setValue (T v, bool setbyuser)
{
Value = v ;
if (setbyuser) {
set = true ;
}
template <class T> void Arg<T>::setValue(T v, bool setbyuser) {
Value = v;
if (setbyuser) {
set = true;
}
}
65 changes: 37 additions & 28 deletions src/Arg.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,39 +32,48 @@
#include <config.h>
#endif

template<class T> class Arg {
public:
Arg (void) : set(false) {} ;
Arg (T v, bool setbyuser = true) ;
template <class T> class Arg {
public:
Arg(void) : set(false){};
Arg(T v, bool setbyuser = true);

T getValue (void) const
{ return Value ; } ;
T getValue(void) const { return Value; };

void setValue (T v, bool setbyuser = true) ;
void setValue(T v, bool setbyuser = true);

bool is_set (void) const
{ return set ; } ;
bool is_set(void) const { return set; };

private:
T Value ;
bool set ;
} ;
private:
T Value;
bool set;
};

enum COMMAND { EMBED, EXTRACT, CRACK, SEED_CRACK, INFO, ENCINFO, SHOWVERSION, SHOWLICENSE, SHOWHELP, PRINTFREQS } ;
enum VERBOSITY { QUIET, NORMAL, VERBOSE, STATS } ;
enum DEBUGCOMMAND { NONE, PRINTGRAPH, PRINTGMLGRAPH, PRINTGMLVERTEX } ;
enum COMMAND {
EMBED,
EXTRACT,
CRACK,
SEED_CRACK,
INFO,
ENCINFO,
SHOWVERSION,
SHOWLICENSE,
SHOWHELP,
PRINTFREQS
};
enum VERBOSITY { QUIET, NORMAL, VERBOSE, STATS };
enum DEBUGCOMMAND { NONE, PRINTGRAPH, PRINTGMLGRAPH, PRINTGMLVERTEX };

typedef Arg<COMMAND> ArgCommand ;
typedef Arg<VERBOSITY> ArgVerbosity ;
typedef Arg<bool> ArgBool ;
typedef Arg<std::string> ArgString ;
typedef Arg<unsigned long> ArgULong ;
typedef Arg<int> ArgInt ;
typedef Arg<float> ArgFloat ;
typedef Arg<EncryptionAlgorithm> ArgEncAlgo ;
typedef Arg<EncryptionMode> ArgEncMode ;
typedef Arg<unsigned int> ArgUInt ;
typedef Arg<std::list<std::string> > ArgStringList ;
typedef Arg<DEBUGCOMMAND> ArgDebugCommand ;
typedef Arg<COMMAND> ArgCommand;
typedef Arg<VERBOSITY> ArgVerbosity;
typedef Arg<bool> ArgBool;
typedef Arg<std::string> ArgString;
typedef Arg<unsigned long> ArgULong;
typedef Arg<int> ArgInt;
typedef Arg<float> ArgFloat;
typedef Arg<EncryptionAlgorithm> ArgEncAlgo;
typedef Arg<EncryptionMode> ArgEncMode;
typedef Arg<unsigned int> ArgUInt;
typedef Arg<std::list<std::string>> ArgStringList;
typedef Arg<DEBUGCOMMAND> ArgDebugCommand;

#endif // ndef SH_ARG_H
Loading

0 comments on commit f8eb63d

Please sign in to comment.