#pragma once #ifndef x12C0DF50_B9FE_11d2_A864_00105A0D0235 #define x12C0DF50_B9FE_11d2_A864_00105A0D0235 /* * Copyright (c) 1998 - 1999 Spokane Software Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software and * its documentation for any purpose is hereby granted without fee, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in any supporting * documentation. Spokane Software Systems makes no representations about * the suitability of this software for any purpose. It is provided "as is" * without express or implied warranty. * */ // Compile time ASSERT, generates compilation error for false argument #define CASSERT(x) \ typedef int x2543F841_A0B2_11d2_AFDF_00105A0D0235[(x) ? 1 : -1]; // Determine the number of elements in an array. #define countof(a) \ (sizeof(::sss::i::countof_validate(a, &(a))) ? sizeof(a) / sizeof((a)[0]) : 0) #define SSS_TRY try #define SSS_UNWIND(action) catch ( ... ) { action; throw; } // According to the standard, wchar_t is a keyword, but for now we // have to do it the Microsoft way #if _MSC_VER <= 1200 #ifndef _WCHAR_T_DEFINED typedef unsigned short wchar_t; #define _WCHAR_T_DEFINED #endif #endif // _MSC_VER namespace sss { namespace i { template void countof_validate(T* const, T* const*) { } template int countof_validate(const void*, T) { } } // namespace i namespace rel_ops { template inline bool operator!=(const T& x, const T& y) { return !(x == y); } template inline bool operator>(const T& x, const T& y) { return y < x; } template inline bool operator<=(const T& x, const T& y) { return !(y < x); } template inline bool operator>=(const T& x, const T& y) { return !(x < y); } } // namespace rel_ops template class pair { typedef pair self; public: typedef X first_type; typedef Y second_type; pair() : first(X()), second(Y()) { } template pair(const U& first, const V& second) : first(first), second(second) { } template pair(const pair& p) : first(p.first), second(p.second) { } template<> pair(const pair& p) : first(p.first), second(p.second) { } template self& operator=(const pair& p) { first = p.first; second = p.second; return *this; } template<> self& operator=(const pair& p) { first = p.first; second = p.second; return *this; } X first; Y second; }; template inline bool operator==(const pair& x, const pair& y) { return x.first == y.first && x.second == y.second; } template inline bool operator!=(const pair& x, const pair& y) { return !(x == y); } template inline bool operator<(const pair& x, const pair& y) { return x.first < y.first || !(y.first < x.first) && x.second < y.second; } template inline bool operator>(const pair& x, const pair& y) { return y < x; } template inline bool operator<=(const pair& x, const pair& y) { return !(y < x); } template inline bool operator>=(const pair& x, const pair& y) { return !(x < y); } template inline pair make_pair(const X& x, const Y& y) { return pair(x, y); } // I thought pair was obnoxious, until I actually had need for a triple. // You could continue this indefinately, but it would get rediculous. template class triple : public pair { typedef pair base; public: typedef Z third_type; triple() : base(X(), Y()), third(Z()) { } template triple(const U& first, const V& second, const W& third) : base(first, second), third(third) { } template triple(const triple& t) : base(t), third(t.third) { } template triple& operator=(const triple& t) { first = t.first; second = t.second; third = t.third; return *this; } friend inline bool operator<(const triple& x, const triple& y) { return static_cast(x) < static_cast(y) || !(static_cast(x) < static_cast(y)) && x.third < y.third; } Z third; }; template inline bool operator==(const triple& x, const triple& y) { return x.first == y.first && x.second == y.second && x.third == y.third; } template inline bool operator!=(const triple& x, const triple& y) { !(x == y); } template inline bool operator>(const triple& x, const triple& y) { return y < x; } template inline bool operator<=(const triple& x, const triple& y) { return !(y < x); } template inline bool operator>=(const triple& x, const triple& y) { return !(x < y); } template inline triple make_triple(const X& x, const Y& y, const Z& z) { return triple(x, y, z); } template class static_object { public: static_object(); ~static_object(); operator T&() const throw(); private: static unsigned space[(sizeof(T) + sizeof(unsigned) - 1) / sizeof(unsigned)]; static unsigned nRefs; }; template inline static_object::static_object() { if ( !nRefs++ ) { new(space) T(); } } template inline static_object::~static_object() { if ( !--nRefs ) { reinterpret_cast(space)->~T(); } } template inline static_object::operator T&() const throw() { return *reinterpret_cast(space); } template unsigned static_object::space[(sizeof(T) + sizeof(unsigned) - 1) / sizeof(unsigned)]; template unsigned static_object::nRefs; struct static_init_t { }; } // namespace sss /* * Copyright (c) 1996,1997 * Silicon Graphics Computer Systems, Inc. * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Silicon Graphics makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * * Copyright (c) 1994 * Hewlett-Packard Company * * Permission to use, copy, modify, distribute and sell this software * and its documentation for any purpose is hereby granted without fee, * provided that the above copyright notice appear in all copies and * that both that copyright notice and this permission notice appear * in supporting documentation. Hewlett-Packard Company makes no * representations about the suitability of this software for any * purpose. It is provided "as is" without express or implied warranty. * */ #endif // x12C0DF50_B9FE_11d2_A864_00105A0D0235