Minsky
minsky::BackgroundSaver Struct Reference

#include <saver.h>

Inheritance diagram for minsky::BackgroundSaver:
Inheritance graph
Collaboration diagram for minsky::BackgroundSaver:
Collaboration graph

Public Member Functions

 BackgroundSaver (const std::string &fileName)
 
 ~BackgroundSaver ()
 
void save (const schema3::Minsky &)
 
void killThread ()
 
- Public Member Functions inherited from minsky::Saver
 Saver (const std::string &fileName)
 
void save (const schema3::Minsky &)
 

Public Attributes

std::thread thread
 
std::string lastError
 
- Public Attributes inherited from minsky::Saver
std::string fileName
 
std::ofstream os
 
classdesc::xml_pack_t packer
 

Detailed Description

Definition at line 45 of file saver.h.

Constructor & Destructor Documentation

◆ BackgroundSaver()

minsky::BackgroundSaver::BackgroundSaver ( const std::string &  fileName)
inline

Definition at line 49 of file saver.h.

49 : Saver(fileName) {}
std::string fileName
Definition: saver.h:38
Saver(const std::string &fileName)
Definition: saver.cc:28

◆ ~BackgroundSaver()

minsky::BackgroundSaver::~BackgroundSaver ( )
inline

Definition at line 50 of file saver.h.

References killThread().

50 {killThread();}
Here is the call graph for this function:

Member Function Documentation

◆ killThread()

void minsky::BackgroundSaver::killThread ( )

Definition at line 59 of file saver.cc.

References minsky::Saver::packer, and thread.

Referenced by save(), and ~BackgroundSaver().

60  {
61  if (thread.joinable())
62  {
63  packer.abort=true;
64  thread.join();
65  }
66  }
std::thread thread
Definition: saver.h:47
classdesc::xml_pack_t packer
Definition: saver.h:40
Here is the caller graph for this function:

◆ save()

void minsky::BackgroundSaver::save ( const schema3::Minsky m)

Definition at line 68 of file saver.cc.

References killThread(), lastError, minsky::Saver::save(), and thread.

69  {
70  killThread();
71  if (!lastError.empty())
72  {
73  lastError.clear();
74  throw std::runtime_error(lastError);
75  }
76  thread=std::thread([this,m](){
77  try
78  {
79  Saver::save(m);
80  }
81  catch (const std::exception& ex) {lastError=ex.what();}
82  catch (...) {} // we don't want any error to propagate
83  });
84  }
std::thread thread
Definition: saver.h:47
void save(const schema3::Minsky &)
Definition: saver.cc:40
std::string lastError
Definition: saver.h:48
Here is the call graph for this function:

Member Data Documentation

◆ lastError

std::string minsky::BackgroundSaver::lastError

Definition at line 48 of file saver.h.

Referenced by save().

◆ thread

std::thread minsky::BackgroundSaver::thread

Definition at line 47 of file saver.h.

Referenced by killThread(), and save().


The documentation for this struct was generated from the following files: