Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
integer_mapping.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/integer_mapping.hh
11 /// @brief A set of useful classes to map between two enumerations. So far, only a subset mapping is implemented.
12 /// @author Andrew Leaver-Fay (aleaverfay@gmail.com)
13 
14 #ifndef INCLUDED_utility_integer_mapping_hh
15 #define INCLUDED_utility_integer_mapping_hh
16 
18 
19 #include <utility/vector1.hh>
21 
22 #include <platform/types.hh>
23 
24 namespace utility {
25 
26 /// @brief This class handles the bookeeping to map between a set of
27 /// integer ids in the "source" enumeration to a subset of those
28 /// ids -- the destination enumartion. Elements in the source enumeration
29 /// that do not map to elements in the destination enumeration
30 /// are represented by the value 0. Both enumerations should
31 /// count from 1. Once the class has been initialized, this class
32 /// offers O(1) mapping between elements in the enumerations.
34 public:
36  static platform::Size const UNMAPPED;
37 
38 public:
40  subset_mapping( platform::Size source_enumeration_size );
41  subset_mapping( subset_mapping const & src );
42  subset_mapping & operator = ( subset_mapping const & rhs );
43 
44  virtual ~subset_mapping();
45 
46  /// @brief Required before the first call to set_next_correspondence may be called.
47  /// The size of the source enumeration must be known before the mapping may begin
49 
50  /// @brief If you know the size of the destination enumeration, then you can save
51  /// some under-the-hood vector resizing operations by informing the subset_mapping
52  /// its size up front. This call must proceed the first call to set_next_correspondence
54 
55  /// @brief Inform the mapping of the next source-enumeration id that should be mapped
56  /// to a destination-enumeration id. This will increase the size of the destination
57  /// enumeration by one. It is not essential that the source-enumeration ids appear
58  /// in sorted order, however, by construction, the destination ids will be in sorted order.
59  void set_next_correspondence( platform::Size source_id );
60 
61  /// @brief The number of elements in the source enumeration
63 
64  /// @brief The number of elements in the destination enumeration -- this
65  /// represents the number of calls that have been made to set_next_correspondence()
67 
68  /// @brief Map from the id of an element in source enumeration to an id in the
69  /// the destination enumeration, which may in fact be UNMAPPED.
70  platform::Size s2d( platform::Size source_id ) const;
71 
72  /// @brief Map from the id of an element in the destination enumeration to an id
73  /// in the source enumeration. This is guaranteed to return a non-zero value.
74  platform::Size d2s( platform::Size destination_id ) const;
75 
76  bool source_id_is_mapped( platform::Size source_id ) const;
77 
78 private:
81 
82 };
83 
84 }
85 
86 #endif
void set_source_size(platform::Size)
Required before the first call to set_next_correspondence may be called. The size of the source enume...
platform::Size s2d(platform::Size source_id) const
Map from the id of an element in source enumeration to an id in the the destination enumeration...
subset_mapping & operator=(subset_mapping const &rhs)
ReferenceCount base class – dispatch class.
platform::Size d2s(platform::Size destination_id) const
Map from the id of an element in the destination enumeration to an id in the source enumeration...
void reserve_destination_size(platform::Size)
If you know the size of the destination enumeration, then you can save some under-the-hood vector res...
bool source_id_is_mapped(platform::Size source_id) const
platform::Size source_size() const
The number of elements in the source enumeration.
void set_next_correspondence(platform::Size source_id)
Inform the mapping of the next source-enumeration id that should be mapped to a destination-enumerati...
static platform::Size const UNMAPPED
utility::pointer::ReferenceCount parent
utility::vector1< platform::Size > dst_2_src_
Base class for reference-counted polymorphic classes.
platform::Size destination_size() const
The number of elements in the destination enumeration – this represents the number of calls that hav...
utility::vector1< platform::Size > src_2_dst_
vector1: std::vector with 1-based indexing
std::size_t Size
Definition: types.hh:37
This class handles the bookeeping to map between a set of integer ids in the "source" enumeration to ...