2004-02-28 20:44:04 +01:00
|
|
|
/*
|
|
|
|
* PROGRAM: Common class definition
|
|
|
|
* MODULE: fb_pair.h
|
|
|
|
* DESCRIPTION: Provides almost that same functionality,
|
|
|
|
* that STL::pair does, but behaves
|
|
|
|
* MemoryPools friendly.
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Initial
|
|
|
|
* Developer's Public License Version 1.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
|
|
|
* http://www.ibphoenix.com/main.nfs?a=ibphoenix&page=ibp_idpl.
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed AS IS,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing rights
|
|
|
|
* and limitations under the License.
|
|
|
|
*
|
|
|
|
* The Original Code was created by Alexander Peshkoff
|
|
|
|
* for the Firebird Open Source RDBMS project.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Alexander Peshkoff <peshkoff@mail.ru>
|
|
|
|
* and all contributors signed below.
|
|
|
|
*
|
|
|
|
* All Rights Reserved.
|
|
|
|
* Contributor(s): ______________________________________.
|
|
|
|
*/
|
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#ifndef CLASSES_FB_PAIR_H
|
|
|
|
#define CLASSES_FB_PAIR_H
|
2004-02-28 20:44:04 +01:00
|
|
|
|
|
|
|
#include "../common/classes/alloc.h"
|
|
|
|
|
|
|
|
namespace Firebird
|
|
|
|
{
|
|
|
|
|
|
|
|
// Left pair - left object in such pair has MemoryPool'ed constructor,
|
|
|
|
// right one - doesn't (typically POD or builtin type)
|
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
template<typename parLeft, typename parRight>
|
|
|
|
struct Left {
|
2004-02-28 20:44:04 +01:00
|
|
|
typedef parLeft first_type;
|
|
|
|
typedef parRight second_type;
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Left(MemoryPool& p) : first(p), second() { }
|
|
|
|
explicit Left(MemoryPool& p, const parLeft& v1, const parRight& v2)
|
2004-03-14 14:24:48 +01:00
|
|
|
: first(p, v1), second(v2) { }
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Left(MemoryPool& p, const Left& lp)
|
2004-03-14 14:24:48 +01:00
|
|
|
: first(p, lp.first), second(lp.second) { }
|
2004-02-28 20:44:04 +01:00
|
|
|
parLeft first;
|
|
|
|
parRight second;
|
|
|
|
};
|
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
// Full pair - both objects in such pair have MemoryPool'ed constructors.
|
2004-02-28 20:44:04 +01:00
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
template<typename parLeft, typename parRight>
|
|
|
|
struct Full {
|
|
|
|
typedef parLeft first_type;
|
|
|
|
typedef parRight second_type;
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Full(MemoryPool& p) : first(p), second(p) { }
|
|
|
|
explicit Full(MemoryPool& p, const parLeft& v1, const parRight& v2)
|
2004-03-14 14:24:48 +01:00
|
|
|
: first(p, v1), second(p, v2) { }
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Full(MemoryPool& p, const Full& lp)
|
2004-03-14 14:24:48 +01:00
|
|
|
: first(p, lp.first), second(p, lp.second) { }
|
|
|
|
parLeft first;
|
|
|
|
parRight second;
|
|
|
|
};
|
2004-02-28 20:44:04 +01:00
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
// Pair - template providing full bool op-s set
|
2004-02-28 20:44:04 +01:00
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
template<typename BasePair>
|
|
|
|
struct Pair : public BasePair {
|
2004-03-15 19:48:10 +01:00
|
|
|
typedef typename Pair::first_type Pair_first_type;
|
|
|
|
typedef typename Pair::second_type Pair_second_type;
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Pair(MemoryPool& p) : BasePair(p) { }
|
|
|
|
explicit Pair(MemoryPool& p, const Pair_first_type& v1,
|
2004-03-15 19:48:10 +01:00
|
|
|
const Pair_second_type& v2) : BasePair(p, v1, v2) { }
|
2004-03-20 15:57:40 +01:00
|
|
|
explicit Pair(MemoryPool& p, const Pair& lp)
|
2004-03-14 14:24:48 +01:00
|
|
|
: BasePair(p, lp) { }
|
|
|
|
Pair() : BasePair(AutoStorage::getAutoMemoryPool()) { }
|
2004-03-15 20:10:44 +01:00
|
|
|
Pair(const Pair_first_type& v1, const Pair_second_type& v2)
|
2004-03-14 14:24:48 +01:00
|
|
|
: BasePair(AutoStorage::getAutoMemoryPool(), v1, v2) { }
|
|
|
|
Pair(const Pair& lp)
|
|
|
|
: BasePair(AutoStorage::getAutoMemoryPool(), lp) { }
|
|
|
|
bool operator==(const Pair& v)
|
|
|
|
{
|
|
|
|
return first == v.first && second == v.second;
|
|
|
|
}
|
|
|
|
bool operator<(const Pair& v)
|
|
|
|
{
|
|
|
|
return first < v.first || (!(first < v.first) && second < v.second);
|
|
|
|
}
|
|
|
|
bool operator!=(const Pair& v)
|
|
|
|
{
|
|
|
|
return ! (*this == v);
|
|
|
|
}
|
|
|
|
bool operator>(const Pair& v)
|
|
|
|
{
|
|
|
|
return v < *this;
|
|
|
|
}
|
|
|
|
bool operator<=(const Pair& v)
|
|
|
|
{
|
|
|
|
return ! (v < *this);
|
|
|
|
}
|
|
|
|
bool operator>=(const Pair& v)
|
|
|
|
{
|
|
|
|
return ! (*this < v);
|
|
|
|
}
|
|
|
|
};
|
2004-02-28 20:44:04 +01:00
|
|
|
|
2004-03-14 14:24:48 +01:00
|
|
|
template <typename P>
|
2004-03-07 08:58:55 +01:00
|
|
|
class FirstKey
|
|
|
|
{
|
2004-02-28 20:44:04 +01:00
|
|
|
public:
|
2004-03-14 14:24:48 +01:00
|
|
|
typedef typename P::first_type Pair_first_type;
|
2004-02-29 06:49:03 +01:00
|
|
|
static const Pair_first_type&
|
2004-03-14 14:24:48 +01:00
|
|
|
generate(void* sender, const P& Item)
|
2004-03-07 08:58:55 +01:00
|
|
|
{
|
|
|
|
return Item.first;
|
|
|
|
}
|
2004-02-28 20:44:04 +01:00
|
|
|
};
|
2004-03-14 14:24:48 +01:00
|
|
|
|
|
|
|
template <typename P>
|
|
|
|
class FirstObjectKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef typename P::first_type Pair_first_type;
|
|
|
|
static const Pair_first_type&
|
|
|
|
generate(void* sender, const P* Item)
|
|
|
|
{
|
|
|
|
return Item->first;
|
|
|
|
}
|
|
|
|
};
|
2004-02-28 20:44:04 +01:00
|
|
|
};
|
|
|
|
|
2004-03-18 06:56:06 +01:00
|
|
|
#endif // CLASSES_FB_PAIR_H
|