20 # pragma warning(push)
21 # pragma warning(disable: 4355)
32 #define THREAD_SAFE_NOTIFY 1
34 #if THREAD_SAFE_NOTIFY
44 class ThreadDataHolder;
73 NOTIFY_LOGONLY = 1 << 7
82 PRINT_SELECTION_END = 8,
83 PRINT_DEFAULT = PRINT_TAG | PRINT_FUNCTION,
84 PRINT_ALL = PRINT_FILE | PRINT_TAG | PRINT_LINE | PRINT_FUNCTION
91 Notify( std::ostream& out_stream = std::cerr);
181 template <
class A, A val >
187 Mode(
Notify* notify ) : m_notify( notify ), m_level( val ) {}
189 Mode(
Notify* notify, A l = val ) : m_notify( notify ), m_level( l ) {}
191 Mode(
const Mode& m ) : m_notify( m.m_notify ), m_level( m.m_level ) {}
196 Notify* getNotify() {
199 const Notify* getNotify()
const {
215 Modifier( Notify* notify ) : m_notify( notify ), m_value( A( 0 ) ) {}
216 Modifier(
const Modifier& m ) : m_notify( m.m_notify ), m_value( m.m_value ) {}
220 Modifier& setValue( A val ) {
225 Notify* getNotify() {
228 const Notify* getNotify()
const {
243 PrintSelection(
int mask );
247 PrintSelection(
const PrintSelection& p );
248 PrintSelection& operator=(
const PrintSelection& p );
255 void setMask(
int f );
258 void setMask(
int f,
bool val );
260 bool isSet(
int s )
const;
262 bool isNoneSet()
const;
265 int m_selection_mask;
271 typedef Mode<Notify::NotifyLevel, Notify::
NOTIFY_END> End;
272 typedef Mode<Notify::NotifyLevel, Notify::
NOTIFY_CLEAR> Clear;
273 typedef Mode<Notify::NotifyLevel, Notify::NOTIFY_LOGONLY> LogOnly;
274 typedef Modifier<
int> Push;
276 SINGLETON_CLASSNAME_METHOD();
279 Notify& operator<<(const T& rhs) {
280 getThreadStringStream() << rhs;
284 typedef std::basic_ostream<char, std::char_traits<char> > CoutType;
285 typedef CoutType& (*StandardEndLine)(CoutType&);
290 operator std::ostream&() {
return getThreadStringStream(); }
293 std::ostringstream& str = getThreadStringStream();
301 Notify&
operator<<( Notify::LogOnly& modifier );
303 std::ios_base::fmtflags setf(std::ios_base::fmtflags newFormatFlags);
306 Clear& clearString() ;
315 void debug(
const char*
function,
int line,
const char* file,
const agx::String& msg );
316 void info(
const char*
function,
int line,
const char* file,
const agx::String& msg );
317 void warning(
const char*
function,
int line,
const char* file,
const agx::String& msg );
318 void error(
const char*
function,
int line,
const char* file,
const agx::String& msg );
326 void pushPrintSelection(
const PrintSelection& p, NotifyLevel l );
328 void pushPrintSelection(
const PrintSelection& p );
331 PrintSelection& getPrintSelection( NotifyLevel l );
333 PrintSelection& getPrintSelection();
336 bool popPrintSelection( NotifyLevel l );
338 bool popPrintSelection();
355 friend class ThreadDataHolder;
357 std::
string str() const;
359 void str( const std::
string& text );
376 std::ostringstream& getThreadStringStream();
377 const std::ostringstream& getThreadStringStream() const;
389 std::ostringstream stream;
395 virtual ~ThreadData();
398 ThreadData* getThreadData();
399 const ThreadData* getThreadData()
const;
404 bool m_throw_on_error;
405 bool m_break_on_error;
407 static Notify* s_instance;
408 std::ostream& m_outStream;
417 #define ADD_NOTIFY_FUNCTIONALITY_TO_CLASS() \
419 void debug( const agx::String& msg ) { Notify::instance()->debug(msg); };\
420 void info( const agx::String& msg ) { Notify::instance()->info(msg); };\
421 void warning( const agx::String& msg ) { Notify::instance()->warning(msg); };\
422 void error( const agx::String& msg ) { Notify::instance()->error(msg); };\
424 void debug( const char* function, int line, const char* file, const agx::String& msg ) { Notify::instance()->debug(function,line,file,msg); };\
425 void info( const char* function, int line, const char* file, const agx::String& msg ) { Notify::instance()->info(function,line,file,msg); };\
426 void warning( const char* function, int line, const char* file, const agx::String& msg ) { Notify::instance()->warning(function,line,file,msg); };\
427 void error( const char* function, int line, const char* file, const agx::String& msg ) { Notify::instance()->error(function,line,file,msg); };\
428 ::agx::Notify::Push push() { return Notify::instance()->push(); };\
429 ::agx::Notify::End end() { return Notify::instance()->end(); };\
430 agx::String setDebugStrings( ::agx::Notify::NotifyLevel l, const char* function, int line, const char* file ) { return Notify::instance()->setDebugStrings(l,function,line,file); };\
432 ::agx::Notify& getNotify() {\
433 ::agx::Notify* n = Notify::instance();\
436 const ::agx::Notify& getNotify() const {\
437 ::agx::Notify* n = Notify::instance();\
443 #define NOTIFY_POS_ARGS __FUNCTION__,__LINE__,__FILE__
445 #define NOTIFY_POS_ARGS "",-1,""
448 #define NOTIFY() getNotify()
449 #define NOTIFY_DEBUG() setDebugStrings(::agx::Notify::NOTIFY_DEBUG, NOTIFY_POS_ARGS)
450 #define NOTIFY_INFO() setDebugStrings(::agx::Notify::NOTIFY_INFO, NOTIFY_POS_ARGS)
451 #define NOTIFY_WARNING() setDebugStrings(::agx::Notify::NOTIFY_WARNING, NOTIFY_POS_ARGS)
452 #define NOTIFY_ERROR() setDebugStrings(::agx::Notify::NOTIFY_ERROR, NOTIFY_POS_ARGS)
453 #define NOTIFY_LOG() logOnly()
454 #define NOTIFY_END() end()
455 #define NOTIFY_CLEAR() clear()
456 #define NOTIFY_STATE(X) push().setValue(X)
459 #define NOTIFY_WARNING_IF_nullptr(X,Y) if ( Y == nullptr ) { X << X.NOTIFY_WARNING() << " nullptr pointer: " << #Y << std::endl << X.NOTIFY_END(); }
460 #define NOTIFY_WARNING_IF_FALSE(X,Y) if ( !Y ) { X << X.NOTIFY_WARNING() << " Test false: " << #Y <<std::endl << X.NOTIFY_END(); }
461 #define NOTIFY_WARNING_IF_TRUE(X,Y) if ( Y ) { X << X.NOTIFY_WARNING() << " Test true: " << #Y <<std::endl << X.NOTIFY_END(); }
463 #define NOTIFY_ERROR_IF_nullptr(X,Y) if ( Y == nullptr ) { X << X.NOTIFY_STATE(::agx::Notify::PRINT_ALL) << X.NOTIFY_ERROR() << " nullptr pointer: " << #Y <<std::endl << X.NOTIFY_END(); }
464 #define NOTIFY_ERROR_IF_FALSE(X,Y) if ( !Y ) { X << X.NOTIFY_STATE(::agx::Notify::PRINT_ALL) << X.NOTIFY_ERROR() << " Test false: " << #Y <<std::endl << X.NOTIFY_END(); }
465 #define NOTIFY_ERROR_IF_TRUE(X,Y) if ( Y ) { X << X.NOTIFY_STATE(::agx::Notify::PRINT_ALL) << X.NOTIFY_ERROR() << " Test true: " << #Y <<std::endl << X.NOTIFY_END(); }
468 #define NOTIFY_INSTANCE() ::agx::Notify::instance()
473 # pragma warning(pop)
#define AGX_DECLARE_POINTER_TYPES(type)
Inheritance with partial specialization due to bug with ref_ptr containers.
Class for printing out messages to console, file, virtual method and or a callback function.
Callback class, derive from this and Register to the notify singleton to get callbacks.
virtual ~NotifyCallback()
virtual void message(const agx::String &msg, int notifyLevel)=0
Virtual method called whenever there is a message ready.
Class for handling logging of messages.
bool getToLogOnly() const
bool setNotifyLevel(NotifyCallback *callback, NotifyLevel l)
Set the notify level for a specific callback.
void addStream(std::ostream *stream, NotifyLevel l)
Add a stream that will be printed to if the notify level less or equal to l, the memory will NOT be m...
const agx::LogStream & logStream() const
std::ostream & outStream()
void setLogNotifyLevel(NotifyLevel l)
Set the notify level for the LogStream.
NotifyLevel getNotifyLevel() const
void setBreakOnError(bool f)
WIN32 specific: If set to true, a breakpoint will be set in debug build.
bool getBreakOnError() const
bool removeCallback(NotifyCallback *callback)
Remove a callback from list of callbacks to report messages to.
bool setNotifyLevel(std::ostream *stream, NotifyLevel l)
Set the notify level for a specific stream.
agx::LogStream & logStream()
bool openLog(const agx::String &filename)
Open a log file (in the LogStream)
void setToLogOnly(bool f)
If f==true, logging will occur only to the LogStream, not to any of the associated ostreams.
NotifyLevel getOutputMode() const
void addCallback(NotifyCallback *callback, NotifyLevel l)
Add a callback class that will be printed to if the notify level less or equal to l.
void setNotifyLevel(NotifyLevel level)
Set the current notify level.
static Notify * instance()
bool removeStream(std::ostream *stream)
Remove a stream from list of streams to report messages to.
void setThrowOnError(bool v)
Specify whether we should Throw an exception upon calling error?
Notify(std::ostream &out_stream=std::cerr)
Constructor.
bool getThrowOnError() const
void setOutputMode(NotifyLevel l)
Set the current output mode, do not use! (used internally)
Base class providing referencing counted objects.
Base class for Singletons that should have its shutdown called explicitly before exit of the applicat...
agx::Thread is a representation of an OS specific implementation of a computational thread.
Smart pointer for handling referenced counted objects.
#define DOXYGEN_END_INTERNAL_BLOCK()
#define DOXYGEN_START_INTERNAL_BLOCK()
Contains function for initialization and shutdown of agxCore library when agxPhysics is not used.
AGXTERRAIN_EXPORT void clear()
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
void AGXCORE_EXPORT setNumThreads(size_t numThreads)
Set the number of threads to use (including the main thread).
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
void AGXPHYSICS_EXPORT shutdown()
Shutdown agx.
std::recursive_mutex ReentrantMutex
std::ostream & operator<<(std::ostream &stream, const AtomicValueT< T > &value)
void AGXPHYSICS_EXPORT init()
Initialize agx.