Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JRedirectAvailable.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JREDIRECTAVAILABLE__
2 #define __JLANG__JREDIRECTAVAILABLE__
3 
4 #include <istream>
5 #include <ostream>
6 
7 #include "JLang/JAnyType.hh"
8 #include "JLang/JNullType.hh"
9 #include "JLang/JTest.hh"
10 #include "JLang/JPrintHelper.hh"
11 
12 
13 /**
14  * \author mdejong
15  */
16 
17 /**
18  * Fallback implementation for <tt>std::istream& operator>>(std::istream, T&)</tt>
19  * for types that don't support the redirect operator.
20  *
21  * \param in input stream
22  * \param any_type any type
23  * \return null type
24  */
25 JLANG::JNullType operator>>(std::istream& in, JLANG::JAnyType any_type);
26 
27 
28 /**
29  * \cond NEVER
30  * Fallback implementation for <tt>std::ostream& operator<<(std::ostream, const T&)</tt>
31  * for types that don't support the redirect operator.
32  *
33  * \param out output stream
34  * \param any_type any type
35  * \return null type
36  * \endcond
37  */
38 //JLANG::JNullType operator<<(std::ostream& out, JLANG::JAnyType any_type);
39 
40 
41 /**
42  * Test availability of redirect operators.
43  */
44 template<class T, bool __str__ = JLANG::JPrintHelper::JMemberMethod<T>::__str__>
46  public JLANG::JTest
47 {
48  using JLANG::JTest::test;
49 
50  static JTrue test(std::istream&);
51  static JTrue test(std::ostream&);
52 
53  static T& getReference();
54 
55  static std::istream& is();
56  static std::ostream& os();
57 
58 public:
59  static const bool has_istream = JTEST(test(is() >> getReference())); //!< true if <tt>std::istream& operator>>(std::istream&, T&)</tt> is defined; else false
60  static const bool has_ostream = JTEST(test(os() << getReference())); //!< true if <tt>std::ostream& operator<<(std::ostream&, const T&)</tt> is defined; else false
61 };
62 
63 
64 /**
65  * Specialisation of JRedirectAvailable for class without member method <tt>__str__</tt>.
66  */
67 template<class T>
68 class JRedirectAvailable<T, true> :
69  public JLANG::JTest
70 {
71 public:
73  static const bool has_ostream = true;
74 };
75 
76 #endif
#define JTEST(__A__)
Test macro.
Definition: JTest.hh:45
std::istream & operator>>(std::istream &in, JHead &header)
Read header from input.
static JFalse test(...)
default false
static JTrue test(std::istream &)
static T & getReference()
static std::ostream & os()
Auxiliary class for any type definition.
Definition: JAnyType.hh:19
Auxiliary base class for compile time evaluation of test.
Definition: JTest.hh:21
definition of true
Definition: JTest.hh:24
Auxiliary class for no type definition.
Definition: JNullType.hh:19
static const bool has_ostream
true if std::ostream&amp; operator&lt;&lt;(std::ostream&amp;, const T&amp;) is defined; else false
static const bool has_istream
true if std::istream&amp; operator&gt;&gt;(std::istream&amp;, T&amp;) is defined; else false
static std::istream & is()
Test availability of redirect operators.