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 Apr 4, 2016
1 parent a5a4677 commit 0a444e1
Show file tree
Hide file tree
Showing 329 changed files with 83,337 additions and 83,568 deletions.
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
66 changes: 38 additions & 28 deletions Base/FileTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <unistd.h>
#endif


/**
* Returns true if given file exists. From http://www.techbytes.ca/techbyte103.html
*/
Expand All @@ -36,9 +35,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 +56,24 @@ 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) {
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,21 +83,21 @@ 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;
if (path2.empty()) return path1;
if (path1.empty())
return path2;
if (path2.empty())
return path1;

const char dirSep = getDirSep();

Expand All @@ -103,50 +106,57 @@ std::string pathJoin(const std::string& path1, const std::string& path2)
return s;
}


std::string pathBasename(const std::string& path)
{
if (path.empty()) return "";
if (path.empty())
return "";

const char dirSep = getDirSep();
const std::string p = rtrim(path, dirSep);

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


std::string pathDirname(const std::string& path)
{
if (path.empty()) return ".";
if (path.empty())
return ".";

const char dirSep = getDirSep();
const std::string p = rtrim(path, dirSep);

const size_t idx = p.find_last_of(dirSep);
if (idx == std::string::npos) {
if (idx == std::string::npos)
{
return "."; // no dirSep in path
} else if (idx == 0) {
}
else if (idx == 0)
{
return std::string(1, dirSep); // only one dirSep at the beginning of path
} else {
}
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 0a444e1

Please sign in to comment.