AGX Dynamics  2.37.3.2
LogListener.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #ifndef AGXSDK_LOGLISTENER_H
18 #define AGXSDK_LOGLISTENER_H
19 
20 #include <agxSDK/agxSDK.h>
22 #include <string>
23 #include <sstream>
24 
25 namespace agxSDK
26 {
27 
30  {
31  public:
32 
33  enum NumberFormat {
36  FIXED
37  };
38 
46  LogListener(const std::string& fileName = "",
47  bool newFilePerTimeStep = false,
48  const std::string& valueSeparator = "\t");
49 
51  virtual void pre(const agx::TimeStamp& /*time*/);
53  virtual void post( const agx::TimeStamp& /*time*/ );
54 
55  inline void setFileName( const std::string& fileName );
56  inline void setNewFilePerTimeStep( bool newFilePerTimeStep );
57  inline void setValueSeparator( const std::string& valueSeparator );
58  inline void setPrecision( int precision );
59  inline void setNumberFormat( NumberFormat format );
60 
61  inline std::string getFileName() const;
62  inline bool getNewFilePerTimeStep() const;
63  inline std::string getValueSeparator() const;
64  inline int getPrecision() const;
65  inline NumberFormat getNumberFormat() const;
66 
67  protected:
69  virtual void obtainHeader( std::stringstream& /*header*/ ) {}
71  virtual void collectData ( std::stringstream& /*data*/, const agx::TimeStamp& /*time*/ ) {}
72 
73  private:
74  void writeToFile( const std::string& text, const agx::TimeStamp& time, bool append );
75 
76 
77  protected:
78  std::string m_fileName;
82  std::string m_separator;
84  };
85 
87 
88 
89  inline void LogListener::setFileName( const std::string& fileName )
90  {
91  m_fileName = fileName;
92  }
93 
94  inline void LogListener::setNewFilePerTimeStep( bool newFilePerTimeStep )
95  {
96  m_newFilePerTimeStep = newFilePerTimeStep;
97  }
98 
99  inline void LogListener::setValueSeparator( const std::string& valueSeparator )
100  {
101  m_separator = valueSeparator;
102  }
103 
104  inline void LogListener::setPrecision( int precision )
105  {
106  m_precision = precision;
107  }
108 
110  {
111  m_format = format;
112  }
113 
114  inline int LogListener::getPrecision() const
115  {
116  return m_precision;
117  }
118 
120  {
121  return m_newFilePerTimeStep;
122  }
123 
124  inline std::string LogListener::getValueSeparator() const
125  {
126  return m_separator;
127  }
128 
129  inline std::string LogListener::getFileName() const
130  {
131  return m_fileName;
132  }
133 
135  {
136  return m_format;
137  }
138 
139 }
140 
141 #endif /* AGXSDK_LOGLISTENER_H */
Derive from this class to implement a listener for simulation step events.
int getPrecision() const
Definition: LogListener.h:114
std::string getFileName() const
Definition: LogListener.h:129
void setNumberFormat(NumberFormat format)
Definition: LogListener.h:109
std::string m_separator
Definition: LogListener.h:82
#define AGXPHYSICS_EXPORT
NumberFormat m_format
Definition: LogListener.h:83
agx::Real TimeStamp
Definition: TimeStamp.h:26
bool getNewFilePerTimeStep() const
Definition: LogListener.h:119
virtual void obtainHeader(std::stringstream &)
Implement this function when inheriting.
Definition: LogListener.h:69
void setNewFilePerTimeStep(bool newFilePerTimeStep)
Definition: LogListener.h:94
void setFileName(const std::string &fileName)
Definition: LogListener.h:89
void setValueSeparator(const std::string &valueSeparator)
Definition: LogListener.h:99
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
std::string m_fileName
Definition: LogListener.h:78
Abstract class for logging properties per time step to a file/standard out.
Definition: LogListener.h:29
void setPrecision(int precision)
Definition: LogListener.h:104
NumberFormat getNumberFormat() const
Definition: LogListener.h:134
agx::ref_ptr< LogListener > LogListenerRef
Definition: LogListener.h:86
std::string getValueSeparator() const
Definition: LogListener.h:124
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
virtual void collectData(std::stringstream &, const agx::TimeStamp &)
Implement this function when inheriting.
Definition: LogListener.h:71