summaryrefslogtreecommitdiff
path: root/libs/audiographer/audiographer/flag_debuggable.h
blob: f5d4fbf6ed5ed6eec222cc736b1af3b9014855ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef AUDIOGRAPHER_FLAG_DEBUGGABLE_H
#define AUDIOGRAPHER_FLAG_DEBUGGABLE_H

#include "audiographer/visibility.h"
#include "debuggable.h"
#include "debug_utils.h"
#include "process_context.h"
#include "types.h"

#include <boost/format.hpp>

namespace AudioGrapher
{

/// A debugging class for nodes that support a certain set of flags.
template<DebugLevel L = DEFAULT_DEBUG_LEVEL>
class /*LIBAUDIOGRAPHER_API*/ FlagDebuggable : public Debuggable<L>
{
  public:
	typedef FlagField::Flag Flag;

  protected:

	/// Adds a flag to the set of flags supported
	void add_supported_flag (Flag flag)
	{
		flags.set (flag);
	}

	/// Prints debug output if \a context contains flags that are not supported by this class
	template<typename SelfType, typename ContextType>
	void check_flags (SelfType & self, ProcessContext<ContextType> context)
	{
		if (!Debuggable<L>::debug_level (DebugFlags)) { return; }
		FlagField unsupported = flags.unsupported_flags_of (context.flags());

		for (FlagField::iterator it = unsupported.begin(); it != unsupported.end(); ++it) {
			Debuggable<L>::debug_stream() << boost::str (boost::format
				("%1% does not support flag %2%")
				% DebugUtils::demangled_name (self) % DebugUtils::process_context_flag_name (*it)
				) << std::endl;
		}
	}

  private:
	FlagField flags;
};


} // namespace

#endif // AUDIOGRAPHER_FLAG_DEBUGGABLE_H