/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* * Main authors: * Guido Tack * * Contributing authors: * Christian Schulte * * Copyright: * Guido Tack, 2007 * Christian Schulte, 2007 * * Last modified: * $Date: 2008-07-11 09:32:27 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $ * $Revision: 7289 $ * * This file is part of Gecode, the generic constraint * development environment: * http://www.gecode.org * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * */ #include namespace Gecode { namespace Support { /** \brief Immutable Symbols * */ class GECODE_SUPPORT_EXPORT Symbol { private: /** \brief Reference-counted Symbol objects * */ class SO { public: /// Duplicate string \a s static char* strdup(const char* s); /// The reference count unsigned int use_cnt; /// Reference counting: cancel subscription bool cancel(void); /// Reference counting: subscribe to an SO void subscribe(void); /// The actual Symbol char* s; /// Whether the SO owns the Symbol bool own; /// Construct from a given Symbol \a s0, which is copied if \a copy is true. SO(const char* s0, bool copy); /// Append \a s0 void append(SO* s0); /// Compare with \a other for equality bool eq(const SO* other) const; /// Compare with \a other for equality bool eq(const char* other) const; /// Return size of the Symbol unsigned int size(void) const; /// Hash value according to modulo \a M int hash(int m) const; /// Output to \a os std::ostream& print(std::ostream& os) const; /// Allocate memory from heap static void* operator new(size_t s); /// Free memory allocated from heap static void operator delete(void* p); }; /// The Symbol object SO* so; public: /// Construct empty Symbol Symbol(void); /// Construct Symbol from \a s0, make a copy if \a copy is true. Symbol(const char* s0, bool copy = false); /// Construct Symbol from \a i Symbol(int i); /// Construct Symbol from \a i Symbol(unsigned int i); /// Copy constructor Symbol(const Symbol& s0); /// Assignment operator const Symbol& operator=(const Symbol& s0); /// Test if this Symbol is equal to \a s0 bool operator==(const Symbol& s0) const; /// Test if this Symbol is equal to \a s0 bool operator==(const char* s0) const; /// Return if Symbol is empty bool empty(void) const; /// Return a copy Symbol copy(void) const; /// Concatenate with \a s Symbol& operator+=(const Symbol& s); /// Hash value according to modulo \a M int hash(int m) const; /// Print this Symbol to \a os std::ostream& print(std::ostream& os) const; /// Return the Symbol as string std::string toString(void) const; /// Destructor GECODE_MSC_VIRTUAL ~Symbol(void); }; }} forceinline std::ostream& operator<<(std::ostream& os, const Gecode::Support::Symbol& x) { return x.print(os); } // STATISTICS: support-any