this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christian Schulte <schulte@gecode.org>
5 *
6 * Copyright:
7 * Christian Schulte, 2016
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.org
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <iostream>
35#include <sstream>
36
37namespace Gecode {
38
39 /**
40 * \brief Print view trace information
41 * \relates ViewTraceInfo
42 */
43 template<class Char, class Traits>
44 std::basic_ostream<Char,Traits>&
45 operator <<(std::basic_ostream<Char,Traits>& os,
46 const ViewTraceInfo& vti) {
47 std::basic_ostringstream<Char,Traits> s;
48 s.copyfmt(os); s.width(0);
49 switch (vti.what()) {
50 case ViewTraceInfo::PROPAGATOR:
51 s << "propagator(id:" << vti.propagator().id();
52 if (vti.propagator().group().in())
53 s << ",g:" << vti.propagator().group().id();
54 s << ')';
55 break;
56 case ViewTraceInfo::BRANCHER:
57 s << "brancher(id:" << vti.brancher().id();
58 if (vti.brancher().group().in())
59 s << ",g:" << vti.brancher().group().id();
60 s << ')';
61 break;
62 case ViewTraceInfo::POST:
63 s << "post(";
64 if (vti.post().in())
65 s << "g:" << vti.post().id();
66 s << ')';
67 break;
68 case ViewTraceInfo::OTHER:
69 s << '-';
70 break;
71 default:
72 GECODE_NEVER;
73 }
74 return os << s.str();
75 }
76
77 /**
78 * \brief Print propagate trace information
79 * \relates PropagateTraceInfo
80 */
81 template<class Char, class Traits>
82 std::basic_ostream<Char,Traits>&
83 operator <<(std::basic_ostream<Char,Traits>& os,
84 const PropagateTraceInfo& pti) {
85 std::basic_ostringstream<Char,Traits> s;
86 s.copyfmt(os); s.width(0);
87 s << "propagate(id:" << pti.id();
88 if (pti.group().in())
89 s << ",g:" << pti.group().id();
90 s << ",s:";
91 switch (pti.status()) {
92 case PropagateTraceInfo::FIX:
93 s << "fix"; break;
94 case PropagateTraceInfo::NOFIX:
95 s << "nofix"; break;
96 case PropagateTraceInfo::FAILED:
97 s << "failed"; break;
98 case PropagateTraceInfo::SUBSUMED:
99 s << "subsumed"; break;
100 default:
101 GECODE_NEVER;
102 }
103 s << ')';
104 return os << s.str();
105 }
106
107 /**
108 * \brief Print commit trace information
109 * \relates CommitTraceInfo
110 */
111 template<class Char, class Traits>
112 std::basic_ostream<Char,Traits>&
113 operator <<(std::basic_ostream<Char,Traits>& os,
114 const CommitTraceInfo& cti) {
115 std::basic_ostringstream<Char,Traits> s;
116 s.copyfmt(os); s.width(0);
117 s << "commit(id:" << cti.id();
118 if (cti.group().in())
119 s << ",g:" << cti.group().id();
120 s << ')';
121 return os << s.str();
122 }
123
124 /**
125 * \brief Print post trace information
126 * \relates PostTraceInfo
127 */
128 template<class Char, class Traits>
129 std::basic_ostream<Char,Traits>&
130 operator <<(std::basic_ostream<Char,Traits>& os,
131 const PostTraceInfo& pti) {
132 std::basic_ostringstream<Char,Traits> s;
133 s.copyfmt(os); s.width(0);
134 s << "post(";
135 if (pti.group().in())
136 s << "g:" << pti.group().id() << ",";
137 s << "s:";
138 switch (pti.status()) {
139 case PostTraceInfo::POSTED:
140 s << "posted(" << pti.propagators() << ")"; break;
141 case PostTraceInfo::FAILED:
142 s << "failed"; break;
143 case PostTraceInfo::SUBSUMED:
144 s << "subsumed"; break;
145 default:
146 GECODE_NEVER;
147 }
148 s << ')';
149 return os << s.str();
150 }
151
152}
153
154// STATISTICS: kernel-trace