Skip to content

Commit

Permalink
apply clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Norihiro Watanabe committed Mar 4, 2016
1 parent ea63401 commit ebf7960
Show file tree
Hide file tree
Showing 326 changed files with 100,521 additions and 88,523 deletions.
42 changes: 21 additions & 21 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
#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
68 changes: 34 additions & 34 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,17 +35,15 @@ 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)
ss << "0";
if (d < 10) ss << "0";
ss << d << ".";
if (m<10)
ss << "0";
if (m < 10) ss << "0";
ss << m << "." << y;
return ss.str();
}
Expand All @@ -55,56 +54,57 @@ 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;
if (d < 10) day = "0" + day;
std::string month = number2str(m);
if (m < 10)
month = "0" + month;
std::string s = number2str(y) + "-" + month + "-" + day;
if (m < 10) month = "0" + month;
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()) );
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()));
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
9 changes: 5 additions & 4 deletions Base/DateTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,15 @@ 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".
* \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
21 changes: 13 additions & 8 deletions Base/FileFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,32 @@ class FileFinder
}

/**
* Given a filename, this method will return the complete path where this file can be found.
* If the file is located in more than one of the directories in the search list, only the
* Given a filename, this method will return the complete path where this
* file can be found.
* If the file is located in more than one of the directories in the search
* list, only the
* first location will be returned.
*/
std::string getPath(std::string filename)
{
if (_directories.empty()) std::cout <<
"Error: FileFinder::getPath() -- directory list is empty." << "\n";
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)
it != _directories.end();
++it)
{
std::string testDir(*it);
std::ifstream is(testDir.append(filename).c_str());
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
#endif // FILEFINDER_H
67 changes: 38 additions & 29 deletions Base/FileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#include <unistd.h>
#endif


/**
* Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
* Returns true if given file exists. From
* http://www.techbytes.ca/techbyte103.html
*/
bool IsFileExisting(std::string const& strFilename)
{
Expand All @@ -36,9 +36,9 @@ bool IsFileExisting(std::string const& strFilename)
int intStat;

// Attempt to get the file attributes
intStat = stat(strFilename.c_str(),&stFileInfo);
intStat = stat(strFilename.c_str(), &stFileInfo);

if(intStat == 0)
if (intStat == 0)
// We were able to get the file attributes
// so the file obviously exists.
blnReturn = true;
Expand All @@ -57,20 +57,25 @@ bool IsFileExisting(std::string const& strFilename)
bool HasCRInLineEnding(std::string const& strFilename)
{
std::ifstream is(strFilename.c_str(), std::ios::in | std::ios::binary);
if (!is) {
std::cout << "*** error: could not open " << strFilename.data() << std::endl;
if (!is)
{
std::cout << "*** error: could not open " << strFilename.data()
<< std::endl;
return false;
}

bool foundCR = false;
while (is.good()) {
while (is.good())
{
char c;
is.read(&c, sizeof(c));
if (c == '\r') {
if (c == '\r')
{
foundCR = true;
break;
}
else if (c == EOF || c == '\n') {
else if (c == EOF || c == '\n')
{
break;
}
}
Expand All @@ -80,17 +85,15 @@ bool HasCRInLineEnding(std::string const& strFilename)
return foundCR;
}


inline char getDirSep()
{
#ifdef WIN32
return '\\';
return '\\';
#else
return '/';
return '/';
#endif
}


std::string pathJoin(const std::string& path1, const std::string& path2)
{
if (path1.empty()) return path2;
Expand All @@ -103,7 +106,6 @@ std::string pathJoin(const std::string& path1, const std::string& path2)
return s;
}


std::string pathBasename(const std::string& path)
{
if (path.empty()) return "";
Expand All @@ -112,14 +114,16 @@ std::string pathBasename(const std::string& path)
const std::string p = rtrim(path, dirSep);

const size_t idx = p.find_last_of(dirSep);
if (idx == std::string::npos) {
return path; // no dirSep in path
} else {
return p.substr(idx+1);
if (idx == std::string::npos)
{
return path; // no dirSep in path
}
else
{
return p.substr(idx + 1);
}
}


std::string pathDirname(const std::string& path)
{
if (path.empty()) return ".";
Expand All @@ -128,25 +132,30 @@ std::string pathDirname(const std::string& path)
const std::string p = rtrim(path, dirSep);

const size_t idx = p.find_last_of(dirSep);
if (idx == std::string::npos) {
return "."; // no dirSep in path
} else if (idx == 0) {
return std::string(1, dirSep); // only one dirSep at the beginning of path
} else {
if (idx == std::string::npos)
{
return "."; // no dirSep in path
}
else if (idx == 0)
{
return std::string(1,
dirSep); // only one dirSep at the beginning of path
}
else
{
return p.substr(0, idx);
}
}


std::string getCwd()
{
char cwd[FILENAME_MAX];
char cwd[FILENAME_MAX];

#ifdef WIN32
_getcwd(cwd, FILENAME_MAX);
_getcwd(cwd, FILENAME_MAX);
#else
getcwd(cwd, FILENAME_MAX);
getcwd(cwd, FILENAME_MAX);
#endif

return cwd;
return cwd;
}
Loading

0 comments on commit ebf7960

Please sign in to comment.