ENH: nicer indentation of inGroups patch entry (issue #474)

- The inGroups is a wordList.
  It can be flattened on output to make files more readable.
This commit is contained in:
Mark Olesen
2017-05-24 07:40:48 +02:00
parent f0fcfce6a3
commit c4caef3a1b
4 changed files with 55 additions and 41 deletions

View File

@ -134,16 +134,18 @@ Foam::coupleGroupIdentifier::coupleGroupIdentifier()
{} {}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const word& name) Foam::coupleGroupIdentifier::coupleGroupIdentifier(const word& patchGroupName)
: :
name_(name) name_(patchGroupName)
{} {}
Foam::coupleGroupIdentifier::coupleGroupIdentifier(const dictionary& dict) Foam::coupleGroupIdentifier::coupleGroupIdentifier(const dictionary& dict)
: :
name_(dict.lookupOrDefault<word>("coupleGroup", "")) name_()
{} {
dict.readIfPresent("coupleGroup", name_);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
@ -222,7 +224,7 @@ void Foam::coupleGroupIdentifier::write(Ostream& os) const
{ {
if (valid()) if (valid())
{ {
os.writeKeyword("coupleGroup") << name() << token::END_STATEMENT << nl; os.writeEntry("coupleGroup", name());
} }
} }
@ -232,7 +234,7 @@ void Foam::coupleGroupIdentifier::write(Ostream& os) const
Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& p) Foam::Ostream& Foam::operator<<(Ostream& os, const coupleGroupIdentifier& p)
{ {
p.write(os); p.write(os);
os.check("Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -53,7 +53,7 @@ class Ostream;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class coupleGroupIdentifier; class coupleGroupIdentifier;
Ostream& operator<<(Ostream&, const coupleGroupIdentifier&); Ostream& operator<<(Ostream& os, const coupleGroupIdentifier& p);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -71,7 +71,11 @@ class coupleGroupIdentifier
// Private Member Functions // Private Member Functions
//- Find other patch in specified mesh. Returns index of patch or -1. //- Find other patch in specified mesh. Returns index of patch or -1.
label findOtherPatchID(const polyMesh&, const polyPatch&) const; label findOtherPatchID
(
const polyMesh& mesh,
const polyPatch& thisPatch
) const;
public: public:
@ -85,7 +89,7 @@ public:
coupleGroupIdentifier(const word& patchGroupName); coupleGroupIdentifier(const word& patchGroupName);
//- Construct from dictionary //- Construct from dictionary
coupleGroupIdentifier(const dictionary&); coupleGroupIdentifier(const dictionary& dict);
// Member Functions // Member Functions
@ -97,19 +101,27 @@ public:
inline bool valid() const; inline bool valid() const;
//- Find other patch in same region. Returns index of patch or -1. //- Find other patch in same region. Returns index of patch or -1.
label findOtherPatchID(const polyPatch&) const; label findOtherPatchID(const polyPatch& thisPatch) const;
//- Find other patch and region. Returns index of patch and sets //- Find other patch and region. Returns index of patch and sets
// otherRegion to name of region. Fatal error if patch not found // otherRegion to name of region. Fatal error if patch not found
label findOtherPatchID(const polyPatch&, word&) const; label findOtherPatchID
(
const polyPatch& thisPatch,
word& otherRegion
) const;
//- Write the data as a dictionary //- Write the data as a dictionary
void write(Ostream&) const; void write(Ostream& os) const;
// IOstream Operators // IOstream Operators
friend Ostream& operator<<(Ostream&, const coupleGroupIdentifier&); friend Ostream& operator<<
(
Ostream& os,
const coupleGroupIdentifier& p
);
}; };

View File

@ -82,7 +82,7 @@ Foam::patchIdentifier::~patchIdentifier()
bool Foam::patchIdentifier::inGroup(const word& name) const bool Foam::patchIdentifier::inGroup(const word& name) const
{ {
return findIndex(inGroups_, name) != -1; return inGroups_.size() && findIndex(inGroups_, name) != -1;
} }
@ -90,23 +90,23 @@ void Foam::patchIdentifier::write(Ostream& os) const
{ {
if (physicalType_.size()) if (physicalType_.size())
{ {
os.writeKeyword("physicalType") << physicalType_ os.writeEntry("physicalType", physicalType_);
<< token::END_STATEMENT << nl;
} }
if (inGroups_.size()) if (inGroups_.size())
{ {
os.writeKeyword("inGroups") << inGroups_ os.writeKeyword("inGroups");
<< token::END_STATEMENT << nl; // Write list with flatOutput
inGroups_.writeList(os, 0) << token::END_STATEMENT << nl;
} }
} }
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
Foam::Ostream& Foam::operator<<(Ostream& os, const patchIdentifier& pi) Foam::Ostream& Foam::operator<<(Ostream& os, const patchIdentifier& p)
{ {
pi.write(os); p.write(os);
os.check("Ostream& operator<<(Ostream&, const patchIdentifier&)"); os.check(FUNCTION_NAME);
return os; return os;
} }

View File

@ -25,7 +25,7 @@ Class
Foam::patchIdentifier Foam::patchIdentifier
Description Description
Identifies patch by name, patch index and physical type Identifies a patch by name, patch index and physical type
SourceFiles SourceFiles
patchIdentifier.C patchIdentifier.C
@ -48,7 +48,7 @@ class dictionary;
// Forward declaration of friend functions and operators // Forward declaration of friend functions and operators
class patchIdentifier; class patchIdentifier;
Ostream& operator<<(Ostream&, const patchIdentifier&); Ostream& operator<<(Ostream& os, const patchIdentifier& p);
/*---------------------------------------------------------------------------*\ /*---------------------------------------------------------------------------*\
@ -68,7 +68,7 @@ class patchIdentifier
//- Optional physical type //- Optional physical type
mutable word physicalType_; mutable word physicalType_;
//- Optional groups patch belongs to //- Optional groups to which the patch belongs
wordList inGroups_; wordList inGroups_;
public: public:
@ -88,14 +88,14 @@ public:
patchIdentifier patchIdentifier
( (
const word& name, const word& name,
const dictionary&, const dictionary& dict,
const label index const label index
); );
//- Construct from geometric patch, resetting the index //- Copy construct from geometric patch, resetting the index
patchIdentifier patchIdentifier
( (
const patchIdentifier&, const patchIdentifier& p,
const label index const label index
); );
@ -106,64 +106,64 @@ public:
// Member Functions // Member Functions
//- Return name //- Return the patch name
const word& name() const const word& name() const
{ {
return name_; return name_;
} }
//- Return name for modification //- Modifiable patch name
word& name() word& name()
{ {
return name_; return name_;
} }
//- Return the optional physical type of the patch //- The optional physical type of the patch
const word& physicalType() const const word& physicalType() const
{ {
return physicalType_; return physicalType_;
} }
//- Return the optional physical type of the patch for modification //- Modifiable optional physical type of the patch
word& physicalType() word& physicalType()
{ {
return physicalType_; return physicalType_;
} }
//- Return the index of this patch in the boundaryMesh //- The index of this patch in the boundaryMesh
label index() const label index() const
{ {
return index_; return index_;
} }
//- Return the index of this patch in the boundaryMesh for modification //- Modifiable the index of this patch in the boundaryMesh
label& index() label& index()
{ {
return index_; return index_;
} }
//- Return the optional groups patch belongs to //- The optional groups that the patch belongs to
const wordList& inGroups() const const wordList& inGroups() const
{ {
return inGroups_; return inGroups_;
} }
//- Return the optional groups patch belongs to for modification //- Modifiable optional groups that the patch belongs to
wordList& inGroups() wordList& inGroups()
{ {
return inGroups_; return inGroups_;
} }
//- Test if in group //- Check if the patch is in named group
bool inGroup(const word&) const; bool inGroup(const word& name) const;
//- Write patchIdentifier as a dictionary //- Write patchIdentifier as a dictionary
void write(Ostream&) const; void write(Ostream& os) const;
// Ostream Operator // Ostream Operator
friend Ostream& operator<<(Ostream&, const patchIdentifier&); friend Ostream& operator<<(Ostream& os, const patchIdentifier& p);
}; };