this repo has no description
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Christopher Mears <chris.mears@monash.edu>
5 *
6 * Copyright:
7 * Christopher Mears, 2012
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 <gecode/int/ldsb.hh>
35
36namespace Gecode {
37 SymmetryHandle::SymmetryHandle(void)
38 : ref(nullptr) {}
39 SymmetryHandle::SymmetryHandle(Int::LDSB::SymmetryObject* o)
40 : ref(o) {}
41 SymmetryHandle::SymmetryHandle(const SymmetryHandle& h)
42 : ref(h.ref) {
43 if (ref != nullptr)
44 increment();
45 }
46 const SymmetryHandle&
47 SymmetryHandle::operator=(const SymmetryHandle& h) {
48 if (h.ref == ref)
49 return *this;
50 if (ref != nullptr)
51 decrement();
52 ref = h.ref;
53 if (ref != nullptr)
54 increment();
55 return *this;
56 }
57 SymmetryHandle::~SymmetryHandle(void) {
58 if (ref != nullptr)
59 decrement();
60 }
61 void
62 SymmetryHandle::increment(void) {
63 (ref->nrefs)++;
64 }
65 void
66 SymmetryHandle::decrement(void) {
67 (ref->nrefs)--;
68 if (ref->nrefs == 0)
69 delete ref;
70 ref = nullptr;
71 }
72}
73
74namespace Gecode { namespace Int { namespace LDSB {
75
76 SymmetryObject::SymmetryObject(void)
77 : nrefs(1) {}
78 SymmetryObject::~SymmetryObject(void) {}
79
80 VariableSymmetryObject::VariableSymmetryObject(ArgArray<VarImpBase*> vars) {
81 nxs = vars.size();
82 xs = new VarImpBase*[nxs];
83 for (int i = 0 ; i < nxs ; i++)
84 xs[i] = vars[i];
85 }
86 VariableSymmetryObject::~VariableSymmetryObject(void) {
87 delete [] xs;
88 }
89
90 ValueSymmetryObject::ValueSymmetryObject(IntSet vs)
91 : values(vs) {}
92
93 VariableSequenceSymmetryObject::
94 VariableSequenceSymmetryObject(ArgArray<VarImpBase*> x, int ss)
95 : seq_size(ss) {
96 nxs = x.size();
97 xs = new VarImpBase*[nxs];
98 for (int i = 0 ; i < nxs ; i++)
99 xs[i] = x[i];
100 }
101 VariableSequenceSymmetryObject::~VariableSequenceSymmetryObject(void) {
102 delete [] xs;
103 }
104
105 ValueSequenceSymmetryObject::ValueSequenceSymmetryObject(IntArgs vs, int ss)
106 : values(vs), seq_size(ss) {}
107
108}}}
109
110// STATISTICS: int-branch