1 #ifndef VIEW_FILE_VIEWER_H_INCLUDED
2 #define VIEW_FILE_VIEWER_H_INCLUDED
22 #include "../../../cpp_simptshell/viewers/common/FileViewerPreferences.h"
23 #include "../../../cpp_simptshell/viewers/common/PreferencesObserver.h"
34 template <
typename FileType>
38 FileViewer(
const std::shared_ptr<SimShell::Ws::MergedPreferences>&);
40 FileViewer(
const std::shared_ptr<SimShell::Ws::MergedPreferences>&, std::string
const & dir_path);
46 template <
typename EventType>
47 void Update(
const EventType& e);
54 std::string MakeFilepath(
const std::string& file_name)
const;
57 std::shared_ptr<prefs_type> m_preferences;
58 std::string m_dir_path;
66 template <
typename FileType>
67 FileViewer<FileType>::FileViewer(
const std::shared_ptr<SimShell::Ws::MergedPreferences>& p)
68 : m_preferences(prefs_type::Create(p)),
69 m_dir_path(p->GetPath()),
70 m_exporter(MakeFilepath(m_preferences->m_file))
74 template <
typename FileType>
75 std::string FileViewer<FileType>::MakeFilepath(
const std::string& file_name)
const
77 std::string
const postfix = FileType::GetFileExtension();
78 std::stringstream file_path;
79 file_path << m_dir_path <<
'/' << file_name <<
"." << postfix;
80 return file_path.str();
83 template <
typename FileType>
84 template <
typename EventType>
88 typename EventType::Source es = e.GetSource();
89 const int step = e.GetStep();
92 const bool check = (et == EventType::Type::Forced)
93 || (et == EventType::Type::Done && m_preferences->m_stride == 0)
94 || (et == EventType::Type::Stepped && ((m_preferences->m_stride != 0) && (step % m_preferences->m_stride == 0)));
97 if (m_exporter.IsOpen() && check) {
104 #endif // end_of_include_guard
Namespace for SimPT shell package.
Type
Enumerates the wall types.
virtual ~FileViewer()
Destructor must be virtual.
void Update(const EventType &e)
Check whether export should happen and then do so.
Interface for MergedPreferences.
Viewer that writes to file and needs to maintain some state info w.r.t.
Listener for SimShell::Event::MergedPreferencesChanged events.