blob: 0f704372e779de3875b20bdd9e141d48a059bdfd [file] [log] [blame]
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -08001/* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil -*- */
2/*
3 * Copyright (c) 2012 University of California, Los Angeles
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Author: Zhenkai Zhu <zhenkai@cs.ucla.edu>
19 * 卞超轶 Chaoyi Bian <bcy@pku.edu.cn>
20 * Alexander Afanasyev <alexander.afanasyev@ucla.edu>
21 */
22
23#ifndef SYNC_DIFF_STATE_CONTAINER_H
24#define SYNC_DIFF_STATE_CONTAINER_H
25
Alexander Afanasyev182fdc22012-03-05 18:06:52 -080026#include "sync-diff-state.h"
Alexander Afanasyeva5858032012-03-09 15:55:10 -080027#include "sync-digest.h"
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080028
29#include <boost/multi_index_container.hpp>
Alexander Afanasyeva5858032012-03-09 15:55:10 -080030#include <boost/multi_index/tag.hpp>
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080031// #include <boost/multi_index/ordered_index.hpp>
32// #include <boost/multi_index/composite_key.hpp>
33#include <boost/multi_index/hashed_index.hpp>
34#include <boost/multi_index/sequenced_index.hpp>
35// #include <boost/multi_index/random_access_index.hpp>
36// #include <boost/multi_index/member.hpp>
37#include <boost/multi_index/mem_fun.hpp>
38
39namespace mi = boost::multi_index;
40
Alexander Afanasyevc1030192012-03-08 22:21:28 -080041namespace Sync {
42
Alexander Afanasyeva5858032012-03-09 15:55:10 -080043struct DigestHash : public std::unary_function<Digest, std::size_t>
44{
45 // std::size_t
46 // operator() (const Digest &digest) const
47 // {
48 // return digest.getHash ();
49 // }
50
51 std::size_t
52 operator() (DigestConstPtr digest) const
53 {
54 return digest->getHash ();
55 }
56};
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080057
Alexander Afanasyevc1030192012-03-08 22:21:28 -080058/// @cond include_hidden
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080059struct sequenced { };
Alexander Afanasyevc1030192012-03-08 22:21:28 -080060/// @endcond
61
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080062/**
63 * \ingroup sync
64 * @brief Container for differential states
65 */
Alexander Afanasyevc1030192012-03-08 22:21:28 -080066struct DiffStateContainer : public mi::multi_index_container<
Alexander Afanasyeva5858032012-03-09 15:55:10 -080067 DiffStatePtr,
68 mi::indexed_by<
69 // For fast access to elements using DiffState hashes
70 mi::hashed_unique<
71 mi::tag<hashed>,
72 mi::const_mem_fun<DiffState, DigestConstPtr, &DiffState::getDigest>,
73 DigestHash
74 >
75 ,
76 // sequenced index to access older/newer element (like in list)
77 mi::sequenced<mi::tag<sequenced> >
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080078 >
Alexander Afanasyeva5858032012-03-09 15:55:10 -080079 >
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080080{
81};
82
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080083} // Sync
Alexander Afanasyev8f25cbb2012-03-01 23:53:40 -080084
85#endif // SYNC_DIFF_STATE_CONTAINER_H