From 5d24a33c484d53e43e18f37241c77ed83a1379e1 Mon Sep 17 00:00:00 2001 From: andy <andy> Date: Fri, 4 Apr 2014 16:38:41 +0100 Subject: [PATCH] ENH: fileName - added isAbsolute function --- .../primitives/strings/fileName/fileName.C | 16 +++++++++++++++- .../primitives/strings/fileName/fileName.H | 13 ++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.C b/src/OpenFOAM/primitives/strings/fileName/fileName.C index 3f24ca74260..965f53edf4f 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.C +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -60,6 +60,20 @@ bool Foam::fileName::isAbsolute() const } +Foam::fileName& Foam::fileName::toAbsolute() +{ + fileName& f = *this; + + if (!f.isAbsolute()) + { + f = cwd()/f; + f.clean(); + } + + return f; +} + + // // * remove repeated slashes // /abc////def --> /abc/def diff --git a/src/OpenFOAM/primitives/strings/fileName/fileName.H b/src/OpenFOAM/primitives/strings/fileName/fileName.H index 3e97853a1f6..d6e9684a7a7 100644 --- a/src/OpenFOAM/primitives/strings/fileName/fileName.H +++ b/src/OpenFOAM/primitives/strings/fileName/fileName.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2013 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -141,11 +141,14 @@ public: // Interrogation - //- Return the file type: FILE, DIRECTORY or UNDEFINED - Type type() const; + //- Return the file type: FILE, DIRECTORY or UNDEFINED + Type type() const; - //- Return true if file name is absolute - bool isAbsolute() const; + //- Return true if file name is absolute + bool isAbsolute() const; + + //- Convert from relative to absolute + fileName& toAbsolute(); // Decomposition -- GitLab