~ubuntu-branches/ubuntu/wily/psi/wily-proposed

« back to all changes in this revision

Viewing changes to third-party/cppunit/cppunit/src/cppunit/Message.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2008-08-28 18:46:52 UTC
  • mfrom: (1.2.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080828184652-iiik12dl91nq7cdi
Tags: 0.12-2
Uploading to unstable (Closes: Bug#494352)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <cppunit/Message.h>
 
2
#include <stdexcept>
 
3
 
 
4
 
 
5
CPPUNIT_NS_BEGIN
 
6
 
 
7
 
 
8
Message::Message()
 
9
{
 
10
}
 
11
 
 
12
Message::Message( const Message &other )
 
13
{
 
14
   *this = other;
 
15
}
 
16
 
 
17
 
 
18
Message::Message( const std::string &shortDescription )
 
19
    : m_shortDescription( shortDescription )
 
20
{
 
21
}
 
22
 
 
23
 
 
24
Message::Message( const std::string &shortDescription,
 
25
                  const std::string &detail1 )
 
26
    : m_shortDescription( shortDescription )
 
27
{
 
28
  addDetail( detail1 );
 
29
}
 
30
 
 
31
 
 
32
Message::Message( const std::string &shortDescription,
 
33
                  const std::string &detail1,
 
34
                  const std::string &detail2 )
 
35
    : m_shortDescription( shortDescription )
 
36
{
 
37
  addDetail( detail1, detail2 );
 
38
}
 
39
 
 
40
 
 
41
Message::Message( const std::string &shortDescription,
 
42
                  const std::string &detail1,
 
43
                  const std::string &detail2,
 
44
                  const std::string &detail3 )
 
45
    : m_shortDescription( shortDescription )
 
46
{
 
47
  addDetail( detail1, detail2, detail3 );
 
48
}
 
49
 
 
50
Message &
 
51
Message::operator =( const Message &other )
 
52
{
 
53
   if ( this != &other )
 
54
   {
 
55
      m_shortDescription = other.m_shortDescription.c_str();
 
56
      m_details.clear();
 
57
      Details::const_iterator it = other.m_details.begin();
 
58
      Details::const_iterator itEnd = other.m_details.end();
 
59
      while ( it != itEnd )
 
60
         m_details.push_back( (*it++).c_str() );
 
61
   }
 
62
 
 
63
   return *this;
 
64
}
 
65
 
 
66
 
 
67
const std::string &
 
68
Message::shortDescription() const
 
69
{
 
70
  return m_shortDescription;
 
71
}
 
72
 
 
73
 
 
74
int 
 
75
Message::detailCount() const
 
76
{
 
77
  return m_details.size();
 
78
}
 
79
 
 
80
 
 
81
std::string 
 
82
Message::detailAt( int index ) const
 
83
{
 
84
  if ( index < 0  ||  index >= detailCount() )
 
85
    throw std::invalid_argument( "Message::detailAt() : invalid index" );
 
86
 
 
87
  return m_details[ index ];
 
88
}
 
89
 
 
90
 
 
91
std::string 
 
92
Message::details() const
 
93
{
 
94
  std::string details;
 
95
  for ( Details::const_iterator it = m_details.begin(); it != m_details.end(); ++it )
 
96
  {
 
97
    details += "- ";
 
98
    details += *it;
 
99
    details += '\n';
 
100
  }
 
101
  return details;
 
102
}
 
103
 
 
104
 
 
105
void 
 
106
Message::clearDetails()
 
107
{
 
108
  m_details.clear();
 
109
}
 
110
 
 
111
 
 
112
void 
 
113
Message::addDetail( const std::string &detail )
 
114
{
 
115
  m_details.push_back( detail );
 
116
}
 
117
 
 
118
 
 
119
void 
 
120
Message::addDetail( const std::string &detail1,
 
121
                    const std::string &detail2 )
 
122
{
 
123
  addDetail( detail1 );
 
124
  addDetail( detail2 );
 
125
}
 
126
 
 
127
 
 
128
void 
 
129
Message::addDetail( const std::string &detail1,
 
130
                    const std::string &detail2,
 
131
                    const std::string &detail3 )
 
132
{
 
133
  addDetail( detail1, detail2 );
 
134
  addDetail( detail3 );
 
135
}
 
136
 
 
137
 
 
138
void 
 
139
Message::addDetail( const Message &message )
 
140
{
 
141
  m_details.insert( m_details.end(), 
 
142
                    message.m_details.begin(), 
 
143
                    message.m_details.end() );
 
144
}
 
145
 
 
146
 
 
147
void 
 
148
Message::setShortDescription( const std::string &shortDescription )
 
149
{
 
150
  m_shortDescription = shortDescription;
 
151
}
 
152
 
 
153
 
 
154
bool 
 
155
Message::operator ==( const Message &other ) const
 
156
{
 
157
  return m_shortDescription == other.m_shortDescription  &&
 
158
         m_details == other.m_details;
 
159
}
 
160
 
 
161
 
 
162
bool 
 
163
Message::operator !=( const Message &other ) const
 
164
{
 
165
  return !( *this == other );
 
166
}
 
167
 
 
168
 
 
169
CPPUNIT_NS_END
 
170