1 /*
2  *  Created by Phil Nash on 1/2/2013.
3  *  Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
4  *
5  *  Distributed under the Boost Software License, Version 1.0. (See accompanying
6  *  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7  */
8 #ifndef TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
9 #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
10 
11 #include <string>
12 #include "catch_result_type.h"
13 #include "catch_common.h"
14 
15 namespace Catch {
16 
17     struct MessageInfo {
18         MessageInfo(    std::string const& _macroName,
19                         SourceLineInfo const& _lineInfo,
20                         ResultWas::OfType _type );
21 
22         std::string macroName;
23         SourceLineInfo lineInfo;
24         ResultWas::OfType type;
25         std::string message;
26         unsigned int sequence;
27 
28         bool operator == ( MessageInfo const& other ) const {
29             return sequence == other.sequence;
30         }
31         bool operator < ( MessageInfo const& other ) const {
32             return sequence < other.sequence;
33         }
34     private:
35         static unsigned int globalCount;
36     };
37 
38     struct MessageBuilder {
MessageBuilderMessageBuilder39         MessageBuilder( std::string const& macroName,
40                         SourceLineInfo const& lineInfo,
41                         ResultWas::OfType type )
42         : m_info( macroName, lineInfo, type )
43         {}
44 
45         template<typename T>
46         MessageBuilder& operator << ( T const& value ) {
47             m_stream << value;
48             return *this;
49         }
50 
51         MessageInfo m_info;
52         std::ostringstream m_stream;
53     };
54 
55     class ScopedMessage {
56     public:
57         ScopedMessage( MessageBuilder const& builder );
58         ScopedMessage( ScopedMessage const& other );
59         ~ScopedMessage();
60 
61         MessageInfo m_info;
62     };
63 
64 } // end namespace Catch
65 
66 #endif // TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED
67