InDesign SDK  20.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
K2Pair.h
1 //========================================================================================
2 //
3 // $File$
4 //
5 // Owner: Mat Marcus (mmarcus)
6 //
7 // $Author$
8 //
9 // $DateTime$
10 //
11 // $Revision$
12 //
13 // $Change$
14 //
15 // ADOBE CONFIDENTIAL. Portions Copyright 2013 Adobe Systems Incorporated. All rights reserved.
16 //
17 // NOTICE: All information contained herein is, and remain the property of Adobe Systems Incorporated
18 // and its suppliers, if any. The intellectual and technical concepts contained herein are proprietary
19 // to Adobe Systems Incorporated and its suppliers and are protected by all applicable intellectual property
20 // laws, including trade secret and copyright laws. Dissemination of this information or reproduction of
21 // this material is strictly forbidden unless prior written permission is obtained from Adobe Systems Incorporated.
22 //
23 // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance
24 // with the terms of the Adobe license agreement accompanying it. If you have received
25 // this file from a source other than Adobe, then your use, modification, or
26 // distribution of it requires the prior written permission of Adobe.
27 //
28 //
29 // Purpose: clone of std::K2Pair based on STLPort 4.0
30 //
31 // This file has been modified by Adobe to meet the needs of the InDesign project.
32 //
33 // Copyright (c) 1994
34 // Hewlett-Packard Company
35 //
36 // Copyright (c) 1996,1997
37 // Silicon Graphics Computer Systems, Inc.
38 //
39 // Copyright (c) 1997
40 // Moscow Center for SPARC Technology
41 //
42 // Copyright (c) 1999
43 // Boris Fomitchev
44 //
45 // This material is provided "as is", with absolutely no warranty expressed
46 // or implied. Any use is at your own risk.
47 //
48 // Permission to use or copy this software for any purpose is hereby granted
49 // without fee, provided the above notices are retained on all copies.
50 // Permission to modify the code and to distribute modified code is granted,
51 // provided the above notices are retained, and a notice that the code was
52 // modified is included with the above copyright notice.
53 //
54 // NOTE: This is an internal header file, included by other STL headers.
55 // You should not attempt to use it directly.
56 //
57 //========================================================================================
58 
59 #ifndef __K2PAIR__
60 #define __K2PAIR__
61 
62 
63 template <class _T1, class _T2>
64 struct K2Pair {
65  typedef object_type data_type; // Could write meta function to declare as base type
66  // if both _T1 and _T2 are base types. But we don't
67  // want to force _T1 and _T2 to declare whether they
68  // are base or objec types.
69  typedef _T1 first_type;
70  typedef _T2 second_type;
71 
72  _T1 first;
73  _T2 second;
74  K2Pair() {}
75  K2Pair(const _T1& __a, const _T2& __b) : first(__a), second(__b) {}
76 
77  template <class _U1, class _U2>
78  K2Pair(const K2Pair<_U1, _U2>& __p) : first(__p.first), second(__p.second) {}
79 
80  K2Pair(const K2Pair<_T1, _T2>& __o) = default;
81  K2Pair(K2Pair<_T1, _T2>&& __o) = default;
82  K2Pair &operator=(const K2Pair<_T1, _T2>& __o) = default;
83  K2Pair &operator=(K2Pair<_T1, _T2>&& __o) = default;
84 
85  friend inline void swap(K2Pair<_T1, _T2>& a, K2Pair<_T1, _T2>& b)
86  {
87  using std::swap;
88  swap(a.first, b.first);
89  swap(a.second, b.second);
90  }
91 
92 };
93 
94 template <class _T1, class _T2>
95 inline bool16 operator==(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y)
96 {
97  return __x.first == __y.first && __x.second == __y.second;
98 }
99 
100 template <class _T1, class _T2>
101 inline bool16 operator<(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y)
102 {
103  return __x.first < __y.first ||
104  (!(__y.first < __x.first) && __x.second < __y.second);
105 }
106 
107 
108 template <class _T1, class _T2>
109 inline bool16 operator!=(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y) {
110  return !(__x == __y);
111 }
112 
113 template <class _T1, class _T2>
114 inline bool16 operator>(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y) {
115  return __y < __x;
116 }
117 
118 template <class _T1, class _T2>
119 inline bool16 operator<=(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y) {
120  return !(__y < __x);
121 }
122 
123 template <class _T1, class _T2>
124 inline bool16 operator>=(const K2Pair<_T1, _T2>& __x, const K2Pair<_T1, _T2>& __y) {
125  return !(__x < __y);
126 }
127 
128 
129 template <class _T1, class _T2>
130 inline K2Pair<_T1, _T2> K2make_pair(const _T1& __x, const _T2& __y)
131 {
132  return K2Pair<_T1, _T2>(__x, __y);
133 }
134 
135 template <class First, class Second>
137  MatchFirstPredicate(const First& first) : fFirst(first) {}
138  bool16 operator()(const K2Pair<First,Second>& x) { return x.first == fFirst; }
139  First fFirst;
140 };
141 
142 template <class First, class Second>
144  MatchSecondPredicate(const Second& second) : fSecond(second) {}
145  bool16 operator()(const K2Pair<First,Second>& x) { return x.second == fSecond; }
146  Second fSecond;
147 };
148 
149 
150 
151 #endif /* __K2PAIR__ */