Skip to content

Commit

Permalink
Merge pull request #188 from OpenBioSim/feature_trajectory_cache
Browse files Browse the repository at this point in the history
Feature trajectory cache
  • Loading branch information
chryswoods authored Apr 24, 2024
2 parents cb69318 + 6dc15cd commit 8cff51b
Show file tree
Hide file tree
Showing 90 changed files with 5,546 additions and 227 deletions.
4 changes: 4 additions & 0 deletions corelib/src/libs/SireBase/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set ( SIREBASE_HEADERS
array2d.hpp
array2d.h
arrayproperty.hpp
atexit.h
booleanproperty.h
chunkedhash.hpp
chunkedvector.hpp
Expand All @@ -46,6 +47,7 @@ set ( SIREBASE_HEADERS
packedarray2d.h
packedarray2d.hpp
packedarrays.h
pagecache.h
pairmatrix.hpp
range.h
ranges.h
Expand Down Expand Up @@ -84,6 +86,7 @@ set ( SIREBASE_SOURCES

array2d.cpp
arrayproperty.cpp
atexit.cpp
booleanproperty.cpp
chunkedhash.cpp
chunkedvector.cpp
Expand All @@ -103,6 +106,7 @@ set ( SIREBASE_SOURCES
meminfo.cpp
numberproperty.cpp
packedarray2d.cpp
pagecache.cpp
parallel.cpp
process.cpp
progressbar.cpp
Expand Down
60 changes: 60 additions & 0 deletions corelib/src/libs/SireBase/atexit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/********************************************\
*
* Sire - Molecular Simulation Framework
*
* Copyright (C) 2024 Christopher Woods
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For full details of the license please see the COPYING file
* that should have come with this distribution.
*
* You can contact the authors via the website
* at https://sire.openbiosim.org
*
\*********************************************/

#include "SireBase/atexit.h"

#include <vector>

#include <QDebug>

namespace SireBase
{
std::vector<std::function<void()>> clean_up_functions;

void clean_up()
{
for (auto &func : clean_up_functions)
{
try
{
func();
}
catch (...)
{
// we can't raise exceptions now, and shouldn't
// print anything, so just fail silently
}
}
}

void register_clean_up_function(std::function<void()> func)
{
clean_up_functions.push_back(func);
}

} // namespace SireBase
81 changes: 81 additions & 0 deletions corelib/src/libs/SireBase/atexit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/********************************************\
*
* Sire - Molecular Simulation Framework
*
* Copyright (C) 2024 Christopher Woods
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* For full details of the license please see the COPYING file
* that should have come with this distribution.
*
* You can contact the authors via the website
* at https://sire.openbiosim.org
*
\*********************************************/

#ifndef SIREBASE_ATEXIT_H
#define SIREBASE_ATEXIT_H

#include "sireglobal.h"

#include <functional>

SIRE_BEGIN_HEADER

namespace SireBase
{
SIREBASE_EXPORT void clean_up();

SIREBASE_EXPORT void register_clean_up_function(std::function<void()> func);

/** This class makes it easier to register a function to be called
* when the program exits. This is useful for cleaning up resources
* that are allocated during the program's execution.
*
* Simply define your function (should be void func() { ... }) and
* then create a static instance of this class with the function as the
* argument. The constructor will be called at library load
* (static initialisation) and the function will be registered to be
* called at exit.
*
* e.g.
*
* void my_exit_function()
* {
* // clean up code here
* }
*
* static RegisterExitFunction my_exit_function_instance(my_exit_function);
*
*/
class SIREBASE_EXPORT RegisterExitFunction
{
public:
RegisterExitFunction(std::function<void()> func)
{
SireBase::register_clean_up_function(func);
}

~RegisterExitFunction() {}
};

} // namespace SireBase

SIRE_EXPOSE_FUNCTION(SireBase::clean_up);

SIRE_END_HEADER

#endif
Loading

0 comments on commit 8cff51b

Please sign in to comment.