From 28f58cb6791216afafbd7a90e463e6f02367d6c8 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 4 Jun 2015 17:09:42 +0100 Subject: [PATCH] IOobject: Added member function "member()" which returns the member name of the object i.e. without the group suffix. Patch provided by William Bainbridge --- src/OpenFOAM/db/IOobject/IOobject.C | 39 ++++++++++++++++------------- src/OpenFOAM/db/IOobject/IOobject.H | 15 +++++++++-- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/OpenFOAM/db/IOobject/IOobject.C b/src/OpenFOAM/db/IOobject/IOobject.C index c6ecf56510..090aea0a01 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.C +++ b/src/OpenFOAM/db/IOobject/IOobject.C @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2014 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -31,23 +31,12 @@ License namespace Foam { -defineTypeNameAndDebug(IOobject, 0); + defineTypeNameAndDebug(IOobject, 0); } // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * // -// Return components following the IOobject requirements -// -// behaviour -// input IOobject(instance, local, name) -// ----- ------ -// "foo" ("", "", "foo") -// "foo/bar" ("foo", "", "bar") -// "/XXX/bar" ("/XXX", "", "bar") -// "foo/bar/" ERROR - no name -// "foo/xxx/bar" ("foo", "xxx", "bar") -// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar") bool Foam::IOobject::fileNameComponents ( const fileName& path, @@ -72,8 +61,7 @@ bool Foam::IOobject::fileNameComponents "fileName&, " "word&" ")" - ) - << " called with directory: " << path << endl; + ) << " called with directory: " << path << endl; return false; } @@ -83,7 +71,7 @@ bool Foam::IOobject::fileNameComponents string::size_type last = path.rfind('/'); instance = path.substr(0, last); - // check afterwards + // Check afterwards name.string::operator=(path.substr(last+1)); } else @@ -114,7 +102,7 @@ bool Foam::IOobject::fileNameComponents } - // check for valid (and stripped) name, regardless of the debug level + // Check for valid (and stripped) name, regardless of the debug level if (name.empty() || string::stripInvalid(name)) { WarningIn @@ -287,6 +275,21 @@ Foam::word Foam::IOobject::group() const } +Foam::word Foam::IOobject::member() const +{ + word::size_type i = name_.find_last_of('.'); + + if (i == word::npos || i == 0) + { + return name_; + } + else + { + return name_.substr(0, i); + } +} + + const Foam::fileName& Foam::IOobject::rootPath() const { return time().rootPath(); @@ -312,7 +315,7 @@ Foam::fileName Foam::IOobject::path const fileName& local ) const { - //Note: can only be called with relative instance since is word type + // Note: can only be called with relative instance since is word type return rootPath()/caseName()/instance/db_.dbDir()/local; } diff --git a/src/OpenFOAM/db/IOobject/IOobject.H b/src/OpenFOAM/db/IOobject/IOobject.H index 098819d5ca..5052f66310 100644 --- a/src/OpenFOAM/db/IOobject/IOobject.H +++ b/src/OpenFOAM/db/IOobject/IOobject.H @@ -2,7 +2,7 @@ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | - \\ / A nd | Copyright (C) 2011-2012 OpenFOAM Foundation + \\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation \\/ M anipulation | ------------------------------------------------------------------------------- License @@ -180,6 +180,14 @@ public: // Static Member Functions //- Split path into instance, local, name components + // input IOobject(instance, local, name) + // ----- ------ + // "foo" ("", "", "foo") + // "foo/bar" ("foo", "", "bar") + // "/XXX/bar" ("/XXX", "", "bar") + // "foo/bar/" ERROR - no name + // "foo/xxx/bar" ("foo", "xxx", "bar") + // "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar") static bool fileNameComponents ( const fileName& path, @@ -320,6 +328,9 @@ public: //- Return group (extension part of name) word group() const; + //- Return member (name without the extension) + word member() const; + const fileName& rootPath() const; const fileName& caseName() const; @@ -432,7 +443,7 @@ Ostream& operator<<(Ostream& os, const InfoProxy& ip); // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // -# include "IOobjectI.H" +#include "IOobjectI.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //