ccmBase.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2016-2020 OpenCFD Ltd.
9 -------------------------------------------------------------------------------
10 License
11  This file is part of OpenFOAM.
12 
13  OpenFOAM is free software: you can redistribute it and/or modify it
14  under the terms of the GNU General Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21  for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25 
26 \*----------------------------------------------------------------------------*/
27 
28 #include "ccmBase.H"
29 #include "ccmInternal.H" // include last to avoid any strange interactions
30 
31 
32 // * * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * //
33 
35 (
36  int err,
37  const char* msg
38 )
39 {
40  return ccmGlobalState::assertNoError(static_cast<CCMIOError>(err), msg);
41 }
42 
43 
45 (
46  int err,
47  const std::string& msg
48 )
49 {
50  return ccmGlobalState::assertNoError(static_cast<CCMIOError>(err), msg);
51 }
52 
53 
54 bool Foam::ccm::base::assertNoError(const char* msg) const
55 {
56  return globalState_->assertNoError(msg);
57 }
58 
59 
60 bool Foam::ccm::base::assertNoError(const std::string& msg) const
61 {
62  return globalState_->assertNoError(msg);
63 }
64 
65 
66 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
67 
69 :
70  globalState_(new ccmGlobalState)
71 {}
72 
73 
74 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
75 
77 {
78  close();
79 }
80 
81 
82 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
83 
85 {
86  if (globalState_)
87  {
88  if (CCMIOIsValidEntity(globalState_->root))
89  {
90  CCMIOCloseFile(nullptr, globalState_->root);
91  }
92  globalState_.reset(nullptr);
93 
94  return true;
95  }
96 
97  return false;
98 }
99 
100 
101 // ************************************************************************* //
Foam::ccm::base::base
base()
Default construct. Initializes the global-state.
Definition: ccmBase.C:68
Foam::ccm::base::globalState_
std::unique_ptr< ccmGlobalState > globalState_
Maintain overall global states (error, root-node)
Definition: ccmBase.H:69
Foam::ccm::base::assertNoError
static bool assertNoError(int err, const char *msg)
Die with msg if there is an error.
Definition: ccmBase.C:35
Foam::ccm::base::close
bool close()
Explicitly close the file and terminate ccmio access.
Definition: ccmBase.C:84
ccmInternal.H
Internal bits for wrapping libccmio - do not use directly.
Foam::ccm::base::~base
~base()
Destructor: close file.
Definition: ccmBase.C:76
ccmBase.H