Generated on Sat Feb 7 2015 02:01:29 for Gecode by doxygen 1.8.9.1
reg.hpp
Go to the documentation of this file.
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, 2008
8  *
9  * Last modified:
10  * $Date: 2008-12-08 12:54:44 +0100 (Mon, 08 Dec 2008) $ by $Author: schulte $
11  * $Revision: 7995 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode {
39 
40  template<class Char, class Traits>
41  std::basic_ostream<Char,Traits>&
42  REG::Exp::print(std::basic_ostream<Char,Traits>& os) const {
43  if (this == NULL)
44  return os << "[]";
45  switch (type) {
46  case ET_SYMBOL:
47  return os << "[" << data.symbol << "]";
48  case ET_STAR:
49  {
50  bool par = ((data.kids[0] != NULL) &&
51  ((data.kids[0]->type == ET_CONC) ||
52  (data.kids[0]->type == ET_OR)));
53  return data.kids[0]->print(os << (par ? "*(" : "*"))
54  << (par ? ")" : "");
55  }
56  case ET_CONC:
57  {
58  bool par0 = ((data.kids[0] != NULL) &&
59  (data.kids[0]->type == ET_OR));
60  std::ostream& os1 = data.kids[0]->print(os << (par0 ? "(" : ""))
61  << (par0 ? ")+" : "+");
62  bool par1 = ((data.kids[1] != NULL) &&
63  (data.kids[1]->type == ET_OR));
64  return data.kids[1]->print(os1 << (par1 ? "(" : "") )
65  << (par1 ? ")" : "");
66  }
67  case ET_OR:
68  return data.kids[1]->print(data.kids[0]->print(os) << "|");
69  default: GECODE_NEVER;
70  }
72  return os;
73  }
74 
75 
76  template<class Char, class Traits>
77  inline std::basic_ostream<Char,Traits>&
78  REG::print(std::basic_ostream<Char,Traits>& os) const {
79  std::basic_ostringstream<Char,Traits> s;
80  s.copyfmt(os); s.width(0);
81  e->print(s);
82  return os << s.str();
83  }
84 
85  template<class Char, class Traits>
86  std::basic_ostream<Char,Traits>&
87  operator <<(std::basic_ostream<Char,Traits>& os, const REG& r) {
88  return r.print(os);
89  }
90 
91 }
92 
93 // STATISTICS: minimodel-any
94 
union Gecode::REG::Exp::@62 data
Symbol or subexpressions.
Regular expressions over integer values.
Definition: minimodel.hh:1401
NNF * r
Right subtree.
Definition: bool-expr.cpp:246
ExpType type
Type of regular expression.
Definition: reg.cpp:72
std::basic_ostream< Char, Traits > & print(std::basic_ostream< Char, Traits > &os) const
Print expression.
Definition: reg.hpp:42
std::basic_ostream< Char, Traits > & print(std::basic_ostream< Char, Traits > &os) const
Print expression.
Definition: reg.hpp:78
Gecode toplevel namespace
#define GECODE_NEVER
Assert that this command is never executed.
Definition: macros.hpp:60