Add clang-format to format (C++) source files automatically (#491)

* Update all CMakeLists of extensions to use clang-format
* Run clang-format on all Extensions
* Update GDCore CMakeLists.txt to add clang-format
* Run clang-format on GDCore files
* Update GDJS and GDCpp CMakeLists.txt to add clang-format
* Run clang-format on GDCpp and GDJS files
This commit is contained in:
Florian Rival
2018-05-09 15:57:38 -07:00
committed by GitHub
parent a77f8e139f
commit a8559bfbbc
866 changed files with 128312 additions and 106701 deletions
+141 -164
View File
@@ -1,214 +1,191 @@
/*
* GDevelop Core
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
* This project is released under the MIT License.
* Copyright 2008-2016 Florian Rival (Florian.Rival@gmail.com). All rights
* reserved. This project is released under the MIT License.
*/
#include "GDCore/String.h"
#include "GDCore/Tools/FileStream.h"
#include <algorithm>
#include "AbstractFileSystem.h"
#include <algorithm>
#include "GDCore/CommonTools.h"
#include "GDCore/IDE/wxTools/RecursiveMkDir.h"
#include "GDCore/String.h"
#include "GDCore/Tools/FileStream.h"
#if !defined(GD_NO_WX_GUI)
#include <fstream>
#include <wx/filename.h>
#include <iostream>
#include <wx/log.h>
#include <wx/filefn.h>
#include <wx/dir.h>
#include <wx/filefn.h>
#include <wx/filename.h>
#include <wx/log.h>
#include <fstream>
#include <iostream>
#endif
#undef CopyFile //Remove a Windows macro
#undef CopyFile // Remove a Windows macro
namespace gd
{
namespace gd {
AbstractFileSystem::~AbstractFileSystem()
{
}
AbstractFileSystem::~AbstractFileSystem() {}
gd::String gd::AbstractFileSystem::NormalizeSeparator(gd::String filename)
{
//Convert all backslash to slashs.
return filename.FindAndReplace("\\", "/");
gd::String gd::AbstractFileSystem::NormalizeSeparator(gd::String filename) {
// Convert all backslash to slashs.
return filename.FindAndReplace("\\", "/");
}
#if !defined(GD_NO_WX_GUI)
NativeFileSystem *NativeFileSystem::singleton = NULL;
gd::String NativeFileSystem::FileNameFrom(const gd::String & file)
{
wxFileName filename = wxFileName::FileName( file );
return filename.GetFullName();
gd::String NativeFileSystem::FileNameFrom(const gd::String &file) {
wxFileName filename = wxFileName::FileName(file);
return filename.GetFullName();
}
gd::String NativeFileSystem::DirNameFrom(const gd::String & file)
{
wxFileName filename = wxFileName::FileName( file );
return filename.GetPath();
gd::String NativeFileSystem::DirNameFrom(const gd::String &file) {
wxFileName filename = wxFileName::FileName(file);
return filename.GetPath();
}
bool NativeFileSystem::IsAbsolute(const gd::String & filename)
{
return wxFileName::FileName(filename).IsAbsolute();
bool NativeFileSystem::IsAbsolute(const gd::String &filename) {
return wxFileName::FileName(filename).IsAbsolute();
}
bool NativeFileSystem::MakeAbsolute(gd::String & fn, const gd::String & baseDirectory)
{
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeAbsolute(baseDirectory);
fn = filename.GetFullPath();
return success;
bool NativeFileSystem::MakeAbsolute(gd::String &fn,
const gd::String &baseDirectory) {
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeAbsolute(baseDirectory);
fn = filename.GetFullPath();
return success;
}
bool NativeFileSystem::MakeRelative(gd::String & fn, const gd::String & baseDirectory)
{
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeRelativeTo(baseDirectory);
if (success)
{
fn = filename.GetFullPath(wxPATH_UNIX);
return true;
}
return false;
}
bool NativeFileSystem::DirExists(const gd::String & path)
{
return wxDirExists(path);
}
bool NativeFileSystem::FileExists(const gd::String & path)
{
return wxFileExists(path);
}
void NativeFileSystem::MkDir(const gd::String & directory)
{
RecursiveMkDir::MkDir(directory);
}
bool NativeFileSystem::ClearDir(const gd::String & directory)
{
wxString file = wxFindFirstFile( directory + "/*" );
while ( !file.empty() )
{
wxRemoveFile( file );
file = wxFindNextFile();
}
bool NativeFileSystem::MakeRelative(gd::String &fn,
const gd::String &baseDirectory) {
wxFileName filename = wxFileName::FileName(fn);
bool success = filename.MakeRelativeTo(baseDirectory);
if (success) {
fn = filename.GetFullPath(wxPATH_UNIX);
return true;
}
return false;
}
gd::String NativeFileSystem::GetTempDir()
{
return wxFileName::GetTempDir();
bool NativeFileSystem::DirExists(const gd::String &path) {
return wxDirExists(path);
}
bool NativeFileSystem::WriteToFile(const gd::String & filename, const gd::String & content)
{
gd::FileStream file( filename, std::ios_base::out );
if ( file.is_open() ) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
bool NativeFileSystem::FileExists(const gd::String &path) {
return wxFileExists(path);
}
gd::String NativeFileSystem::ReadFile(const gd::String & file)
{
gd::FileStream t( file, std::ios_base::in );
std::stringstream buffer;
buffer << t.rdbuf();
return gd::String::FromUTF8(buffer.str());
void NativeFileSystem::MkDir(const gd::String &directory) {
RecursiveMkDir::MkDir(directory);
}
bool NativeFileSystem::ClearDir(const gd::String &directory) {
wxString file = wxFindFirstFile(directory + "/*");
while (!file.empty()) {
wxRemoveFile(file);
file = wxFindNextFile();
}
std::vector<gd::String> NativeFileSystem::ReadDir(const gd::String & path, const gd::String & extension)
{
std::vector<gd::String> results;
wxString upperExt = wxString(extension).Upper();
wxString file = wxFindFirstFile( path + "/*" );
while ( !file.empty() )
{
if ( upperExt.empty() || file.Upper().EndsWith(upperExt) )
results.push_back(file);
file = wxFindNextFile();
}
return results;
return true;
}
bool NativeFileSystem::CopyFile(const gd::String & file, const gd::String & destination)
{
if (file == destination) return true; //No copy needed
gd::String NativeFileSystem::GetTempDir() { return wxFileName::GetTempDir(); }
wxLogNull noLogPlease;
return wxCopyFile( file, destination, true );
}
bool NativeFileSystem::CopyDir(const gd::String & source, const gd::String & destination)
{
wxString sFrom = source.ToWxString();
wxString sTo = destination.ToWxString();
//As seen on https://forums.wxwidgets.org/viewtopic.php?t=2080
if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/') sFrom += wxFILE_SEP_PATH;
if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/') sTo += wxFILE_SEP_PATH;
if (!::wxDirExists(sFrom)) {
return false;
}
if (!wxDirExists(sTo)) {
if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) {
return false;
}
}
wxDir fDir(sFrom);
wxString sNext = wxEmptyString;
bool bIsFile = fDir.GetFirst(&sNext);
while (bIsFile) {
const wxString sFileFrom = sFrom + sNext;
const wxString sFileTo = sTo + sNext;
if (::wxDirExists(sFileFrom)) {
CopyDir(sFileFrom, sFileTo);
}
else {
if (!::wxFileExists(sFileTo)) {
if (!::wxCopyFile(sFileFrom, sFileTo)) {
return false;
}
}
}
bIsFile = fDir.GetNext(&sNext);
}
bool NativeFileSystem::WriteToFile(const gd::String &filename,
const gd::String &content) {
gd::FileStream file(filename, std::ios_base::out);
if (file.is_open()) {
file << content.ToUTF8();
file.close();
return true;
}
return false;
}
NativeFileSystem & NativeFileSystem::Get()
{
if ( !singleton ) singleton = new NativeFileSystem;
return *singleton;
gd::String NativeFileSystem::ReadFile(const gd::String &file) {
gd::FileStream t(file, std::ios_base::in);
std::stringstream buffer;
buffer << t.rdbuf();
return gd::String::FromUTF8(buffer.str());
}
void NativeFileSystem::DestroySingleton()
{
if ( singleton )
{
delete singleton;
singleton = NULL;
std::vector<gd::String> NativeFileSystem::ReadDir(const gd::String &path,
const gd::String &extension) {
std::vector<gd::String> results;
wxString upperExt = wxString(extension).Upper();
wxString file = wxFindFirstFile(path + "/*");
while (!file.empty()) {
if (upperExt.empty() || file.Upper().EndsWith(upperExt))
results.push_back(file);
file = wxFindNextFile();
}
return results;
}
bool NativeFileSystem::CopyFile(const gd::String &file,
const gd::String &destination) {
if (file == destination) return true; // No copy needed
wxLogNull noLogPlease;
return wxCopyFile(file, destination, true);
}
bool NativeFileSystem::CopyDir(const gd::String &source,
const gd::String &destination) {
wxString sFrom = source.ToWxString();
wxString sTo = destination.ToWxString();
// As seen on https://forums.wxwidgets.org/viewtopic.php?t=2080
if (sFrom[sFrom.Len() - 1] != '\\' && sFrom[sFrom.Len() - 1] != '/')
sFrom += wxFILE_SEP_PATH;
if (sTo[sTo.Len() - 1] != '\\' && sTo[sTo.Len() - 1] != '/')
sTo += wxFILE_SEP_PATH;
if (!::wxDirExists(sFrom)) {
return false;
}
if (!wxDirExists(sTo)) {
if (!wxFileName::Mkdir(sTo, 0777, wxPATH_MKDIR_FULL)) {
return false;
}
}
wxDir fDir(sFrom);
wxString sNext = wxEmptyString;
bool bIsFile = fDir.GetFirst(&sNext);
while (bIsFile) {
const wxString sFileFrom = sFrom + sNext;
const wxString sFileTo = sTo + sNext;
if (::wxDirExists(sFileFrom)) {
CopyDir(sFileFrom, sFileTo);
} else {
if (!::wxFileExists(sFileTo)) {
if (!::wxCopyFile(sFileFrom, sFileTo)) {
return false;
}
}
}
bIsFile = fDir.GetNext(&sNext);
}
return true;
}
NativeFileSystem::~NativeFileSystem()
{
NativeFileSystem &NativeFileSystem::Get() {
if (!singleton) singleton = new NativeFileSystem;
return *singleton;
}
void NativeFileSystem::DestroySingleton() {
if (singleton) {
delete singleton;
singleton = NULL;
}
}
NativeFileSystem::~NativeFileSystem() {}
#endif
}
} // namespace gd