Skip to content

Commit 6dfa480

Browse files
authored
of::filesystem to fs, removing using namespace std (#337)
#changelog #filesystem
1 parent 007fe56 commit 6dfa480

File tree

6 files changed

+89
-82
lines changed

6 files changed

+89
-82
lines changed

commandLine/src/main.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ constexpr option::Descriptor usage[] =
2626
#include "androidStudioProject.h"
2727
#include "Utils.h"
2828

29+
namespace fs = of::filesystem;
2930

3031
#define EXIT_OK 0
3132
#define EXIT_USAGE 64
@@ -458,7 +459,7 @@ int main(int argc, char* argv[]){
458459
ofPath = ofPathEnv;
459460
}
460461

461-
currentWorkingDirectory = of::filesystem::current_path().string();
462+
currentWorkingDirectory = fs::current_path().string();
462463

463464
if (ofPath == "") {
464465

@@ -475,9 +476,9 @@ int main(int argc, char* argv[]){
475476
} else {
476477

477478
// convert ofpath from relative to absolute by appending this to current path and calculating .. by canonical.
478-
// FIXME: convert ofPath and functions to of::filesystem::path
479-
if (!of::filesystem::path(ofPath).is_absolute()) {
480-
ofPath = of::filesystem::canonical(of::filesystem::current_path() / of::filesystem::path(ofPath)).string();
479+
// FIXME: convert ofPath and functions to fs::path
480+
if (!fs::path(ofPath).is_absolute()) {
481+
ofPath = fs::canonical(fs::current_path() / fs::path(ofPath)).string();
481482
}
482483

483484

@@ -508,7 +509,7 @@ int main(int argc, char* argv[]){
508509
if (ofFilePath::isAbsolute(projectName)) {
509510
projectPath = projectName;
510511
} else {
511-
projectPath = of::filesystem::absolute(projectName).string();
512+
projectPath = fs::absolute(projectName).string();
512513
}
513514
} else {
514515
ofLogError() << "Missing project path";

ofxProjectGenerator/src/addons/ofAddon.cpp

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
//#include "Poco/RegularExpression.h"
1313
#include <list>
1414
#include <regex>
15-
using namespace std;
15+
16+
using std::vector;
17+
using std::string;
18+
namespace fs = of::filesystem;
1619

1720
vector<string> splitStringOnceByLeft(const string &source, const string &delimiter) {
1821
size_t pos = source.find(delimiter);
@@ -179,7 +182,7 @@ void ofAddon::addReplaceStringVector(std::vector<std::string> & variable, std::s
179182
varValue = getenv(varName.c_str());
180183
}
181184
ofStringReplace(values[i],"$("+varName+")",varValue);
182-
ofLogVerbose("ofAddon") << "addon config: substituting " << varName << " with " << varValue << " = " << values[i] << endl;
185+
ofLogVerbose("ofAddon") << "addon config: substituting " << varName << " with " << varValue << " = " << values[i] << std::endl;
183186
}
184187
}
185188

@@ -216,7 +219,7 @@ void ofAddon::addReplaceStringVector(vector<LibraryBinary> & variable, string va
216219
varValue = getenv(varName.c_str());
217220
}
218221
ofStringReplace(values[i],"$("+varName+")",varValue);
219-
ofLogVerbose("ofAddon") << "addon config: substituting " << varName << " with " << varValue << " = " << values[i] << endl;
222+
ofLogVerbose("ofAddon") << "addon config: substituting " << varName << " with " << varValue << " = " << values[i] << std::endl;
220223
}
221224
}
222225

@@ -240,7 +243,7 @@ void ofAddon::parseVariableValue(string variable, string value, bool addToValue,
240243
}
241244

242245

243-
of::filesystem::path addonRelPath;
246+
fs::path addonRelPath;
244247
if (!isLocalAddon) {
245248
// addonRelPath = ofFilePath::addTrailingSlash(pathToOF) + "addons/" + name;
246249
addonRelPath = pathToOF / "addons" / name;
@@ -474,12 +477,12 @@ void ofAddon::parseConfig(){
474477
}
475478
}
476479

477-
bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
480+
bool ofAddon::fromFS(fs::path path, const std::string & platform){
478481
clear();
479482
this->platform = platform;
480483

481-
of::filesystem::path prefixPath;
482-
of::filesystem::path containedPath;
484+
fs::path prefixPath;
485+
fs::path containedPath;
483486

484487
if(isLocalAddon){
485488
name = path.stem().string();
@@ -506,15 +509,15 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
506509

507510
// FIXME: srcFiles to fs::path
508511
for (auto & s : srcFiles) {
509-
of::filesystem::path folder;
512+
fs::path folder;
510513
if (isLocalAddon) {
511514
// FIXME: test if local addons is working ok
512-
folder = of::filesystem::path("local_addons") / of::filesystem::path(s).parent_path();
515+
folder = fs::path("local_addons") / fs::path(s).parent_path();
513516
} else {
514-
folder = of::filesystem::path(s).parent_path();
515-
folder = of::filesystem::relative(folder, containedPath);
517+
folder = fs::path(s).parent_path();
518+
folder = fs::relative(folder, containedPath);
516519
}
517-
s = of::filesystem::path(prefixPath / of::filesystem::relative(s, containedPath)).string();
520+
s = fs::path(prefixPath / fs::relative(s, containedPath)).string();
518521
filesToFolders[s] = folder.string();
519522
}
520523

@@ -525,20 +528,20 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
525528

526529
// FIXME: propsFiles to fs::path
527530
for (auto & s : propsFiles) {
528-
of::filesystem::path folder;
531+
fs::path folder;
529532
if (isLocalAddon) {
530533
// FIXME: test if local addons is working ok
531-
folder = of::filesystem::path("local_addons") / of::filesystem::path(s).parent_path();
534+
folder = fs::path("local_addons") / fs::path(s).parent_path();
532535
} else {
533-
folder = of::filesystem::path(s).parent_path();
534-
folder = of::filesystem::relative(folder, containedPath);
536+
folder = fs::path(s).parent_path();
537+
folder = fs::relative(folder, containedPath);
535538
}
536-
s = of::filesystem::path(prefixPath / of::filesystem::relative(s, containedPath)).string();
539+
s = fs::path(prefixPath / fs::relative(s, containedPath)).string();
537540
}
538541

539542
// for (int i = 0; i < (int)propsFiles.size(); i++) {
540543
// propsFiles[i].erase(propsFiles[i].begin(), propsFiles[i].begin() + containedPath.string().length());
541-
// int end = propsFiles[i].rfind(of::filesystem::path("/").make_preferred().string());
544+
// int end = propsFiles[i].rfind(fs::path("/").make_preferred().string());
542545
// int init = 0;
543546
// string folder;
544547
// if (!isLocalAddon) {
@@ -552,7 +555,7 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
552555
// }
553556

554557

555-
of::filesystem::path libsPath = path / "libs";
558+
fs::path libsPath = path / "libs";
556559
vector < string > libFiles;
557560

558561
if (ofDirectory(libsPath).exists()){
@@ -569,31 +572,31 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
569572

570573

571574
for (auto & s : libFiles) {
572-
of::filesystem::path folder;
575+
fs::path folder;
573576
if (isLocalAddon) {
574577
// FIXME: test if local addons is working ok
575-
folder = of::filesystem::path("local_addons") / of::filesystem::path(s).parent_path();
578+
folder = fs::path("local_addons") / fs::path(s).parent_path();
576579
} else {
577-
folder = of::filesystem::path(s).parent_path();
578-
folder = of::filesystem::relative(folder, containedPath);
580+
folder = fs::path(s).parent_path();
581+
folder = fs::relative(folder, containedPath);
579582
}
580-
s = of::filesystem::path(prefixPath / of::filesystem::relative(s, containedPath)).string();
583+
s = fs::path(prefixPath / fs::relative(s, containedPath)).string();
581584
srcFiles.emplace_back(s);
582585
filesToFolders[s] = folder.string();
583586
}
584587

585588

586589
// changing libs folder from absolute to relative.
587590
for (auto & l : libs) {
588-
l.path = of::filesystem::path(prefixPath / of::filesystem::relative(l.path, containedPath)).string();
591+
l.path = fs::path(prefixPath / fs::relative(l.path, containedPath)).string();
589592
}
590593

591594

592595
// for (int i = 0; i < (int)libs.size(); i++){
593596
//
594597
// cout << "libs path before " << libs[i].path << endl;
595598
// // does libs[] have any path ? let's fix if so.
596-
// int end = libs[i].path.rfind(of::filesystem::path("/").make_preferred().string());
599+
// int end = libs[i].path.rfind(fs::path("/").make_preferred().string());
597600
// if (end > 0){
598601
// libs[i].path.erase (libs[i].path.begin(), libs[i].path.begin() + containedPath.string().length());
599602
// libs[i].path = prefixPath.string() + libs[i].path;
@@ -624,7 +627,7 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
624627
frameworks[i].erase (frameworks[i].begin(), frameworks[i].begin() + containedPath.string().length());
625628

626629
int init = 0;
627-
int end = frameworks[i].rfind(of::filesystem::path("/").make_preferred().string());
630+
int end = frameworks[i].rfind(fs::path("/").make_preferred().string());
628631

629632
string folder;
630633
if (!isLocalAddon) {
@@ -644,7 +647,7 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
644647
}
645648

646649
// paths that are needed for the includes.
647-
list < of::filesystem::path > paths;
650+
std::list < fs::path > paths;
648651

649652
// get every folder in addon/src and addon/libs
650653
vector < string > libFolders;
@@ -659,11 +662,11 @@ bool ofAddon::fromFS(of::filesystem::path path, const std::string & platform){
659662

660663
// convert paths to relative
661664
for (auto & l : libFolders) {
662-
paths.push_back({ prefixPath / of::filesystem::relative(of::filesystem::path(l), containedPath) });
665+
paths.push_back({ prefixPath / fs::relative(fs::path(l), containedPath) });
663666
}
664667

665668
for (auto & l : srcFolders) {
666-
paths.push_back({ prefixPath / of::filesystem::relative(of::filesystem::path(l), containedPath) });
669+
paths.push_back({ prefixPath / fs::relative(fs::path(l), containedPath) });
667670
}
668671

669672
paths.sort(); //paths.unique(); // unique not needed anymore. everything is carefully inserted now.

ofxProjectGenerator/src/projects/baseProject.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@
1212
#include "Utils.h"
1313
#include "ofConstants.h"
1414
#include <list>
15-
using namespace std;
1615

17-
baseProject::baseProject(string _target){
16+
using std::string;
17+
using std::vector;
18+
//using std::cout;
19+
//using std::endl;
20+
namespace fs = of::filesystem;
21+
22+
const std::string templatesFolder = "scripts/templates/";
23+
24+
baseProject::baseProject(std::string _target){
1825
bLoaded = false;
1926
target = _target;
2027
}
2128

22-
const std::string templatesFolder = "scripts/templates/";
23-
2429
std::string baseProject::getPlatformTemplateDir(){
2530
return ofFilePath::join(getOFRoot(),templatesFolder + target);
2631
}
@@ -47,7 +52,7 @@ bool isPlatformName(std::string file){
4752
}
4853

4954
std::unique_ptr<baseProject::Template> baseProject::parseTemplate(const ofDirectory & templateDir){
50-
auto name = of::filesystem::path(templateDir.getOriginalDirectory()).parent_path().filename();
55+
auto name = fs::path(templateDir.getOriginalDirectory()).parent_path().filename();
5156
if(templateDir.isDirectory() && !isPlatformName(name)){
5257
ofBuffer templateconfig;
5358
ofFile templateconfigFile(ofFilePath::join(templateDir.path(), "template.config"));
@@ -94,8 +99,8 @@ std::unique_ptr<baseProject::Template> baseProject::parseTemplate(const ofDirect
9499
return std::unique_ptr<baseProject::Template>();
95100
}
96101

97-
vector<baseProject::Template> baseProject::listAvailableTemplates(std::string target){
98-
vector<baseProject::Template> templates;
102+
std::vector<baseProject::Template> baseProject::listAvailableTemplates(std::string target){
103+
std::vector<baseProject::Template> templates;
99104

100105
ofDirectory templatesDir(ofFilePath::join(getOFRoot(),templatesFolder));
101106
for(auto & f: templatesDir.getSorted()){
@@ -109,14 +114,14 @@ vector<baseProject::Template> baseProject::listAvailableTemplates(std::string ta
109114
return templates;
110115
}
111116

112-
bool baseProject::create(const of::filesystem::path & _path, std::string templateName){
117+
bool baseProject::create(const fs::path & _path, std::string templateName){
113118
templatePath = getPlatformTemplateDir();
114119
addons.clear();
115120
extSrcPaths.clear();
116121
auto path = _path;
117122

118123
if(!ofFilePath::isAbsolute(path)){
119-
path = (of::filesystem::current_path() / of::filesystem::path(path)).string();
124+
path = (fs::current_path() / fs::path(path)).string();
120125
}
121126
projectDir = path;
122127

@@ -160,12 +165,12 @@ bool baseProject::create(const of::filesystem::path & _path, std::string templat
160165

161166
if (bDoesDirExist){
162167

163-
vector < string > fileNames;
168+
std::vector < string > fileNames;
164169
getFilesRecursively(projectDir / "src", fileNames);
165170

166171
for (auto & f : fileNames) {
167-
of::filesystem::path rel { of::filesystem::relative(f, projectDir) };
168-
of::filesystem::path folder { rel.parent_path() };
172+
fs::path rel { fs::relative(f, projectDir) };
173+
fs::path folder { rel.parent_path() };
169174

170175
std::string fileName = rel.string();
171176

@@ -182,9 +187,9 @@ bool baseProject::create(const of::filesystem::path & _path, std::string templat
182187
}
183188

184189
// only add unique paths
185-
std::vector < of::filesystem::path > paths;
190+
std::vector < fs::path > paths;
186191
for (auto & f : fileNames) {
187-
auto dir = of::filesystem::path(f).parent_path().filename();
192+
auto dir = fs::path(f).parent_path().filename();
188193
if (std::find(paths.begin(), paths.end(), dir) == paths.end()) {
189194
paths.emplace_back(dir);
190195
// cout << "addInclude " << dir << endl;
@@ -201,9 +206,9 @@ bool baseProject::save(){
201206
ofFile addonsMake(ofFilePath::join(projectDir,"addons.make"), ofFile::WriteOnly);
202207
for(int i = 0; i < addons.size(); i++){
203208
if(addons[i].isLocalAddon){
204-
addonsMake << of::filesystem::path(addons[i].addonPath).generic_string() << endl;
209+
addonsMake << fs::path(addons[i].addonPath).generic_string() << std::endl;
205210
}else{
206-
addonsMake << addons[i].name << endl;
211+
addonsMake << addons[i].name << std::endl;
207212
}
208213
}
209214

@@ -224,18 +229,18 @@ bool baseProject::save(){
224229
path = getOFRelPath(projectDir);
225230
}
226231

227-
saveConfig << "OF_ROOT = " << path << endl;
232+
saveConfig << "OF_ROOT = " << path << std::endl;
228233
}
229234
// replace this section with our external paths
230235
else if( extSrcPaths.size() && str.rfind("# PROJECT_EXTERNAL_SOURCE_PATHS =", 0) == 0 ){
231236

232237
for(int d = 0; d < extSrcPaths.size(); d++){
233-
ofLog(OF_LOG_VERBOSE) << " adding PROJECT_EXTERNAL_SOURCE_PATHS to config" << extSrcPaths[d] << endl;
234-
saveConfig << "PROJECT_EXTERNAL_SOURCE_PATHS" << (d == 0 ? " = " : " += ") << extSrcPaths[d] << endl;
238+
ofLog(OF_LOG_VERBOSE) << " adding PROJECT_EXTERNAL_SOURCE_PATHS to config" << extSrcPaths[d] << std::endl;
239+
saveConfig << "PROJECT_EXTERNAL_SOURCE_PATHS" << (d == 0 ? " = " : " += ") << extSrcPaths[d] << std::endl;
235240
}
236241

237242
}else{
238-
saveConfig << str << endl;
243+
saveConfig << str << std::endl;
239244
}
240245
}
241246
}
@@ -308,10 +313,10 @@ void baseProject::addAddon(std::string addonName){
308313

309314
for(auto& d : addon.data){
310315

311-
of::filesystem::path path(ofFilePath::join(addon.addonPath, d));
316+
fs::path path(ofFilePath::join(addon.addonPath, d));
312317

313-
if(of::filesystem::exists(path)){
314-
if (of::filesystem::is_regular_file(path)){
318+
if(fs::exists(path)){
319+
if (fs::is_regular_file(path)){
315320
ofFile src({path});
316321
string dest = ofFilePath::join(projectDir, "bin/data/");
317322
ofStringReplace(d, "data/", ""); // avoid to copy files at /data/data/*
@@ -321,7 +326,7 @@ void baseProject::addAddon(std::string addonName){
321326
}else {
322327
ofLogWarning() << "Can not add addon data file: " << d;
323328
}
324-
}else if(of::filesystem::is_directory(path)){
329+
}else if(fs::is_directory(path)){
325330
ofDirectory dir({path});
326331
string dest = ofFilePath::join(projectDir, "bin/data/");
327332
ofStringReplace(d, "data/", ""); // avoid to copy files at /data/data/*
@@ -388,7 +393,7 @@ void baseProject::addSrcRecursively(std::string srcPath){
388393
if( !ofFilePath::isAbsolute(absPath) ){
389394
absPath = ofFilePath::getAbsolutePath( ofFilePath::join(ofFilePath::getCurrentExeDir(), fileToAdd) );
390395
}
391-
auto canPath = of::filesystem::canonical(absPath); //resolves the ./ and ../ to be the most minamlist absolute path
396+
auto canPath = fs::canonical(absPath); //resolves the ./ and ../ to be the most minamlist absolute path
392397

393398
//get the file path realtive to the project
394399
auto projectPath = ofFilePath::getAbsolutePath( projectDir );
@@ -414,7 +419,7 @@ void baseProject::addSrcRecursively(std::string srcPath){
414419
//do it this way so we don't try and add a include folder for each file ( as it checks if they are already added ) so should be faster
415420
for(auto & includeFolder : uniqueIncludeFolders){
416421
ofLogVerbose() << " adding search include paths for folder " << includeFolder.second;
417-
cout << "includeFolder.second " << includeFolder.second << endl;
422+
// cout << "includeFolder.second " << includeFolder.second << endl;
418423
addInclude(includeFolder.second);
419424
}
420425
}

0 commit comments

Comments
 (0)