summaryrefslogtreecommitdiff
path: root/TAO/CIAO/CCF/CCF/CompilerElements/DiagnosticStream.hpp
blob: 6561095690c6c0c93c3ee5ce7608930675d06b00 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// file      : CCF/Runtime/DiagnosticStream.hpp
// author    : Boris Kolpackov <boris@dre.vanderbilt.edu>
// cvs-id    : $Id$

#ifndef CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H
#define CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H

#include "MSVC_Pragmas.hpp"

#include <string>
#include <sstream>

#include "CCF/CompilerElements/ExH.hpp"

namespace CCF
{
  namespace Runtime
  {
    namespace Diagnostic
    {
      class Message
      {
      public:
        virtual
        ~Message () throw ();

        virtual std::string
        text () const throw (ExH::System::Exception) = 0;
      };

      class Stream
      {
      public:
        Stream () throw ();
        virtual
        ~Stream () throw ();

      public:
        Stream& operator<< (Message const& msg)
          throw (ExH::System::Exception);

      private:
        // Copy semanic is not supported.
        Stream (Stream const&) throw ();
        Stream& operator= (Stream const&) throw ();
      };

      extern Stream dout;

      //
      // Concrete Message classes.
      //

      template <typename Category>
      class MessageImpl : public virtual Message,
                          public virtual Category
      {
      public:
        MessageImpl (char const* subject, char const* message)
          throw (ExH::System::Exception)
            : subject_ (subject), message_ (message) {}

        MessageImpl (char const* subject, std::ostringstream const& message)
          throw (ExH::System::Exception)
            : subject_ (subject), message_ (message.str ()) {}

        virtual
        ~MessageImpl () throw () {}

        virtual std::string
        text () const throw (ExH::System::Exception)
        {
          std::string category = Category::name ();

          if (category.empty ())
          {
            return subject_ + ": " + message_;
          }
          else
          {
            return subject_ + ": " + category + ": " + message_;
          }
        }

      private:
        std::string subject_;
        std::string message_;
      };

      //
      // Error
      //

      struct ErrorCategory
      {
        virtual ~ErrorCategory () throw () {}

        std::string name () const throw (ExH::System::Exception)
        {
          return "error";
        }
      };

      typedef MessageImpl<ErrorCategory> Error;

      //
      // Warning
      //

      struct WarningCategory
      {
        virtual ~WarningCategory () throw () {}

        std::string name () const throw (ExH::System::Exception)
        {
          return "warning";
        }
      };

      typedef MessageImpl<WarningCategory> Warning;

      //
      // Information
      //

      struct InformationCategory
      {
        virtual ~InformationCategory () throw () {}

        std::string name () const throw (ExH::System::Exception)
        {
          return "";
        }
      };

      typedef MessageImpl<InformationCategory> Information;
    }
  }
}

#endif  // CCF_RUNTIME_DIAGNOSTIC_DIAGNOSTIC_STREAM_H