Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Applying Clang format #16

Merged
merged 7 commits into from
Apr 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
25 changes: 25 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
Language: Cpp
BasedOnStyle: Google

AccessModifierOffset: -4
AlignTrailingComments: false
AllowShortBlocksOnASingleLine: false
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
BreakBeforeBinaryOperators: true
BreakBeforeBraces: Allman
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine : false
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: true
IndentWidth: 4
PointerAlignment: Left
Standard: Cpp03
SpacesBeforeTrailingComments: 1
TabWidth: 4
UseTab: ForIndentation

# ACTIVATE IF VERSION >= 3.8
#SortIncludes: false
74 changes: 44 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
# Ubuntu 14.04 Trusty support
sudo: required
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment: Jobs requiring sudo are slower (see Boot Time) but otherwise you can not use apt-get install.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unfortunately OpenMPI and PETSc installation requires apt-get install because the packages are not in their white list (as far as I tested)

dist: trusty

language: cpp
#dist: trusty
compiler:
- gcc
os:
- linux
cache:
- apt
compiler: gcc

# workaround to exclude the default job
env:
- CASE=FEM
# - CASE=SP
# - CASE=PQC
- CASE=IPQC
- CASE=GEMS
- CASE=LIS CMAKE_ARGS="-DLIS_INCLUDE_DIR=$TRAVIS_BUILD_DIR/lis-cmake-master/include -DLIS_LIBRARIES=$TRAVIS_BUILD_DIR/lis-cmake-master/build/lib/liblis.a"
- CASE=MPI
- CASE=PETSC CMAKE_ARGS="-DPETSC_DIR=/usr/lib/petscdir/3.4.2/"

before_install:
# -- External package sources --
- if [[ "$CASE" == "GEMS" ]]; then travis_retry sudo add-apt-repository --yes ppa:boost-latest; fi
- if [[ "$CASE" == "PETSC" ]]; then travis_retry sudo add-apt-repository --yes ppa:feelpp/petsc; fi
- travis_retry sudo apt-get update -qq;
matrix:
- TRAVIS_EMPTY_JOB_WORKAROUND=true

matrix:
exclude:
- env: TRAVIS_EMPTY_JOB_WORKAROUND=true

include:
# # check coding style
# - env: CASE=codingstyle
# addons:
# apt:
# sources:
# - llvm-toolchain-precise-3.7
# - ubuntu-toolchain-r-test
# packages:
# - clang-format-3.7
# check typical OGS builds
- env: CASE=FEM
- env: CASE=IPQC
- env: CASE=GEMS
addons:
apt:
sources:
- boost-latest
packages:
- libboost-thread1.55-dev
- env: CASE=LIS CMAKE_ARGS="-DLIS_INCLUDE_DIR=$TRAVIS_BUILD_DIR/lis-cmake-master/include -DLIS_LIBRARIES=$TRAVIS_BUILD_DIR/lis-cmake-master/build/lib/liblis.a"
addons:
apt:
packages:
- gfortran
- env: CASE=MPI
- env: CASE=PETSC CMAKE_ARGS="-DPETSC_DIR=/usr/lib/petscdir/3.4.2/"

install:
# GEMS
- if [[ "$CASE" == "GEMS" ]]; then travis_retry sudo apt-get install -qq libboost-thread1.55-dev; fi
# Lis
- if [[ "$CASE" == "LIS" ]]; then sudo apt-get install -qq gfortran; fi
- if [[ "$CASE" == "LIS" ]]; then wget https://github.com/norihiro-w/lis-cmake/archive/master.zip; fi
- if [[ "$CASE" == "LIS" ]]; then unzip master.zip && cd lis-cmake-master; fi
- if [[ "$CASE" == "LIS" ]]; then mkdir build && cd build && cmake .. && make && cd ../..; fi
# MPI
- if [[ "$CASE" == "MPI" ]]; then travis_retry sudo apt-get install -qq openmpi-bin openmpi-dev; fi
- if [[ "$CASE" == "MPI" ]]; then travis_retry sudo apt-get install -qq openmpi-bin libopenmpi-dev; fi
# PETSC
- if [[ "$CASE" == "PETSC" ]]; then travis_retry sudo apt-get install -qq libpetsc3.4.2-dev; fi

script:
- mkdir build
- cd build
- cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic ..
- cmake ..
- make
- if [[ "$CASE" != "codingstyle" ]]; then mkdir build && cd build && cmake -DOGS_CONFIG=${CASE} $CMAKE_ARGS -DOGS_CPU_ARCHITECTURE=generic .. && cmake ..; fi
- if [[ "$CASE" != "codingstyle" ]]; then make; fi
# - if [[ "$CASE" == "codingstyle" ]]; then chmod +x ./scripts/ci/check_code_format.sh && ./scripts/ci/check_code_format.sh; fi

notifications:
email:
Expand Down
40 changes: 20 additions & 20 deletions Base/BuildInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@

namespace BuildInfo
{
extern const std::string GIT_COMMIT_INFO;
extern const std::string GIT_BRANCH_INFO;
extern const std::string BUILD_TIMESTAMP;
extern const std::string CMAKE_SYSTEM;
extern const std::string CMAKE_SYSTEM_PROCESSOR;
extern const std::string CMAKE_CXX_COMPILER;
extern const std::string GCC_VERSION;
extern const std::string CMAKE_GENERATOR;
extern const std::string CMAKE_BUILD_TYPE;
extern const std::string CMAKE_CXX_FLAGS;
extern const std::string CMAKE_CXX_FLAGS_RELEASE;
extern const std::string CMAKE_CXX_FLAGS_DEBUG;
extern const std::string SOLVER_PACKAGE_NAME;
extern const std::string GIT_COMMIT_INFO;
extern const std::string GIT_BRANCH_INFO;
extern const std::string BUILD_TIMESTAMP;
extern const std::string CMAKE_SYSTEM;
extern const std::string CMAKE_SYSTEM_PROCESSOR;
extern const std::string CMAKE_CXX_COMPILER;
extern const std::string GCC_VERSION;
extern const std::string CMAKE_GENERATOR;
extern const std::string CMAKE_BUILD_TYPE;
extern const std::string CMAKE_CXX_FLAGS;
extern const std::string CMAKE_CXX_FLAGS_RELEASE;
extern const std::string CMAKE_CXX_FLAGS_DEBUG;
extern const std::string SOLVER_PACKAGE_NAME;

extern const std::string SOURCEPATH;
extern const std::string BUILDPATH;
extern const std::string TESTDATAPATH;
extern const std::string OGS_VERSION;
extern const std::string OGS_DATE;
extern const std::string OGS_EXECUTABLE;
extern const std::string PUT_TMP_DIR_IN;
extern const std::string SOURCEPATH;
extern const std::string BUILDPATH;
extern const std::string TESTDATAPATH;
extern const std::string OGS_VERSION;
extern const std::string OGS_DATE;
extern const std::string OGS_EXECUTABLE;
extern const std::string PUT_TMP_DIR_IN;
}

#endif // BUILDINFO_H
2 changes: 1 addition & 1 deletion Base/CorrectScientificNotationMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
#include "StringTools.h"

int main( int argc, const char* argv[] )
int main(int argc, const char* argv[])
{
if (argc < 2)
{
Expand Down
59 changes: 32 additions & 27 deletions Base/DateTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

int date2int(int y, int m, int d)
{
if ( (y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31) )
if ((y < 1000 || y > 9999) || (m < 1 || m > 12) || (d < 1 || d > 31))
{
std::cout << "Error: date2double() -- input not in expected format." << "\n";
std::cout << "Error: date2double() -- input not in expected format."
<< "\n";
return 0;
}

Expand All @@ -34,16 +35,16 @@ int date2int(int y, int m, int d)

std::string int2date(int date)
{
if (date>10000000 && date<22000000)
if (date > 10000000 && date < 22000000)
{
int y = static_cast<int>(floor(date/10000.0));
int m = static_cast<int>(floor((date-(y*10000))/100.0));
int d = date-(y*10000)-(m*100);
int y = static_cast<int>(floor(date / 10000.0));
int m = static_cast<int>(floor((date - (y * 10000)) / 100.0));
int d = date - (y * 10000) - (m * 100);
std::stringstream ss;
if (d<10)
if (d < 10)
ss << "0";
ss << d << ".";
if (m<10)
if (m < 10)
ss << "0";
ss << m << "." << y;
return ss.str();
Expand All @@ -55,56 +56,60 @@ std::string date2string(double ddate)
{
if (ddate < 10000101 || ddate > 99991231)
{
std::cout << "Error: date2String() -- input not in expected format." << "\n";
std::cout << "Error: date2String() -- input not in expected format."
<< "\n";
return "0.0.0000";
}

int rest (static_cast<int>(ddate));
int rest(static_cast<int>(ddate));
int y = static_cast<int>(floor(rest / 10000.0));
rest = rest % (y * 10000);
int m = static_cast<int>(floor(rest / 100.0));
if (m < 1 || m > 12)
std::cout << "Warning: date2String() -- month not in [1:12]" << "\n";
std::cout << "Warning: date2String() -- month not in [1:12]"
<< "\n";
rest = rest % (m * 100);
int d = rest;
if (d < 1 || d > 31)
std::cout << "Warning: date2String() -- day not in [1:31]" << "\n";
std::cout << "Warning: date2String() -- day not in [1:31]"
<< "\n";

std::string day = number2str(d);
if (d < 10)
day = "0" + day;
std::string month = number2str(m);
if (m < 10)
month = "0" + month;
std::string s = number2str(y) + "-" + month + "-" + day;
std::string s = number2str(y) + "-" + month + "-" + day;
return s;
}

int strDate2int(const std::string &s)
int strDate2int(const std::string& s)
{
std::string str(s);
if (s.length() > 10)
str = s.substr(0,10);
size_t sep ( str.find(".",0) );
int d ( atoi(str.substr(0, sep).c_str()) );
size_t sep2 ( str.find(".", sep + 1) );
int m ( atoi(str.substr(sep + 1,sep2 - (sep + 1)).c_str()) );
int y ( atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str()) );
str = s.substr(0, 10);
size_t sep(str.find(".", 0));
int d(atoi(str.substr(0, sep).c_str()));
size_t sep2(str.find(".", sep + 1));
int m(atoi(str.substr(sep + 1, sep2 - (sep + 1)).c_str()));
int y(atoi(str.substr(sep2 + 1, s.length() - (sep2 + 1)).c_str()));
return date2int(y, m, d);
}

int xmlDate2int(const std::string &s)
int xmlDate2int(const std::string& s)
{
if (s.length() == 10)
{
int d = atoi(s.substr(8,2).c_str());
int d = atoi(s.substr(8, 2).c_str());
if (d < 1 || d > 31)
std::cout << "Warning: xmlDate2double() -- day not in [1:31]" << "\n";
int m = atoi(s.substr(5,2).c_str());
std::cout << "Warning: xmlDate2double() -- day not in [1:31]"
<< "\n";
int m = atoi(s.substr(5, 2).c_str());
if (m < 1 || m > 12)
std::cout << "Warning: xmlDate2double() -- month not in [1:12]" <<
"\n";
int y = atoi(s.substr(0,4).c_str());
std::cout << "Warning: xmlDate2double() -- month not in [1:12]"
<< "\n";
int y = atoi(s.substr(0, 4).c_str());
return date2int(y, m, d);
}
return 0;
Expand Down
6 changes: 3 additions & 3 deletions Base/DateTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ std::string date2string(double ddate);
* \param s String containing the date, the expected format is "dd.mm.yyyy".
* \return A number representing the date as dd.mm.yyyy.
*/
int strDate2int(const std::string &s);
int strDate2int(const std::string& s);

/**
* Converts a string containing a date into a double.
* Note: It is not really checked if the date actually makes sense.
* \param s String containing the date, the expected format is conform to the xml date type, i.e. "yyyy-mm-dd".
* \return A number representing the date as yyyymmdd.
*/
int xmlDate2int(const std::string &s);
int xmlDate2int(const std::string& s);

#endif //DATETOOLS_H
#endif // DATETOOLS_H
19 changes: 10 additions & 9 deletions Base/FileFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ class FileFinder
public:
/// Constructor
FileFinder() {}

/**
* \brief Adds another directory to the search-space.
* If the given directory does not end with a slash one will be appended.
*/
void addDirectory(std::string dir)
{
if (dir[dir.size() - 1] != '/') dir.append("/");
if (dir[dir.size() - 1] != '/')
dir.append("/");
_directories.push_back(dir);
}

Expand All @@ -44,21 +44,22 @@ class FileFinder
*/
std::string getPath(std::string filename)
{
if (_directories.empty()) std::cout <<
"Error: FileFinder::getPath() -- directory list is empty." << "\n";
for (std::list<std::string>::iterator it = _directories.begin();
it != _directories.end(); ++it)
if (_directories.empty())
std::cout << "Error: FileFinder::getPath() -- directory list is empty."
<< "\n";
for (std::list<std::string>::iterator it = _directories.begin(); it != _directories.end(); ++it)
{
std::string testDir(*it);
std::ifstream is(testDir.append(filename).c_str());
if (is.good()) return testDir;
if (is.good())
return testDir;
}
std::cout << "Error: FileFinder::getPath() -- file not found." << "\n";
std::cout << "Error: FileFinder::getPath() -- file not found."
<< "\n";
return filename;
}

private:

std::list<std::string> _directories;
};
#endif // FILEFINDER_H
Loading