1 | /* Used in Boost.MultiIndex tests. |
---|
2 | * |
---|
3 | * Copyright 2003-2005 Joaquín M López Muñoz. |
---|
4 | * Distributed under the Boost Software License, Version 1.0. |
---|
5 | * (See accompanying file LICENSE_1_0.txt or copy at |
---|
6 | * http://www.boost.org/LICENSE_1_0.txt) |
---|
7 | * |
---|
8 | * See http://www.boost.org/libs/multi_index for library home page. |
---|
9 | */ |
---|
10 | |
---|
11 | #ifndef BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP |
---|
12 | #define BOOST_MULTI_INDEX_TEST_EMPLOYEE_HPP |
---|
13 | |
---|
14 | #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */ |
---|
15 | #include <boost/multi_index_container.hpp> |
---|
16 | #include <boost/multi_index/hashed_index.hpp> |
---|
17 | #include <boost/multi_index/identity.hpp> |
---|
18 | #include <boost/multi_index/member.hpp> |
---|
19 | #include <boost/multi_index/ordered_index.hpp> |
---|
20 | #include <boost/multi_index/sequenced_index.hpp> |
---|
21 | #include <cstddef> |
---|
22 | #include <ostream> |
---|
23 | #include <string> |
---|
24 | |
---|
25 | struct employee |
---|
26 | { |
---|
27 | int id; |
---|
28 | std::string name; |
---|
29 | int age; |
---|
30 | int ssn; |
---|
31 | |
---|
32 | employee(int id_,std::string name_,int age_,int ssn_): |
---|
33 | id(id_),name(name_),age(age_),ssn(ssn_) |
---|
34 | {} |
---|
35 | |
---|
36 | bool operator==(const employee& x)const |
---|
37 | { |
---|
38 | return id==x.id&&name==x.name&&age==x.age; |
---|
39 | } |
---|
40 | |
---|
41 | bool operator<(const employee& x)const |
---|
42 | { |
---|
43 | return id<x.id; |
---|
44 | } |
---|
45 | |
---|
46 | bool operator!=(const employee& x)const{return !(*this==x);} |
---|
47 | bool operator> (const employee& x)const{return x<*this;} |
---|
48 | bool operator>=(const employee& x)const{return !(*this<x);} |
---|
49 | bool operator<=(const employee& x)const{return !(x<*this);} |
---|
50 | |
---|
51 | struct comp_id |
---|
52 | { |
---|
53 | bool operator()(int x,const employee& e2)const{return x<e2.id;} |
---|
54 | bool operator()(const employee& e1,int x)const{return e1.id<x;} |
---|
55 | }; |
---|
56 | |
---|
57 | friend std::ostream& operator<<(std::ostream& os,const employee& e) |
---|
58 | { |
---|
59 | os<<e.id<<" "<<e.name<<" "<<e.age<<std::endl; |
---|
60 | return os; |
---|
61 | } |
---|
62 | }; |
---|
63 | |
---|
64 | struct name{}; |
---|
65 | struct by_name{}; |
---|
66 | struct age{}; |
---|
67 | struct as_inserted{}; |
---|
68 | struct ssn{}; |
---|
69 | |
---|
70 | typedef |
---|
71 | boost::multi_index::multi_index_container< |
---|
72 | employee, |
---|
73 | boost::multi_index::indexed_by< |
---|
74 | boost::multi_index::ordered_unique< |
---|
75 | boost::multi_index::identity<employee> >, |
---|
76 | boost::multi_index::hashed_non_unique< |
---|
77 | boost::multi_index::tag<name,by_name>, |
---|
78 | BOOST_MULTI_INDEX_MEMBER(employee,std::string,name)>, |
---|
79 | boost::multi_index::ordered_non_unique< |
---|
80 | boost::multi_index::tag<age>, |
---|
81 | BOOST_MULTI_INDEX_MEMBER(employee,int,age)>, |
---|
82 | boost::multi_index::sequenced< |
---|
83 | boost::multi_index::tag<as_inserted> >, |
---|
84 | boost::multi_index::hashed_unique< |
---|
85 | boost::multi_index::tag<ssn>, |
---|
86 | BOOST_MULTI_INDEX_MEMBER(employee,int,ssn)> > > |
---|
87 | employee_set; |
---|
88 | |
---|
89 | #if defined(BOOST_NO_MEMBER_TEMPLATES) |
---|
90 | typedef boost::multi_index::nth_index< |
---|
91 | employee_set,1>::type employee_set_by_name; |
---|
92 | #else |
---|
93 | typedef employee_set::nth_index<1>::type employee_set_by_name; |
---|
94 | #endif |
---|
95 | |
---|
96 | typedef boost::multi_index::index< |
---|
97 | employee_set,age>::type employee_set_by_age; |
---|
98 | typedef boost::multi_index::index< |
---|
99 | employee_set,as_inserted>::type employee_set_as_inserted; |
---|
100 | typedef boost::multi_index::index< |
---|
101 | employee_set,ssn>::type employee_set_by_ssn; |
---|
102 | |
---|
103 | #endif |
---|