Rosetta 3.5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Interval.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 protocols/forge/build/instructions/Interval.fwd.hh
11 /// @brief simple struct defining a closed interval of residues
12 /// @author Yih-En Andrew Ban (yab@u.washington.edu)
13 
14 #ifndef INCLUDED_protocols_forge_build_Interval_hh
15 #define INCLUDED_protocols_forge_build_Interval_hh
16 
17 // unit headers
19 
20 // project headers
21 #include <core/types.hh>
22 
23 // C++ headers
24 #include <cassert>
25 
26 namespace protocols {
27 namespace forge {
28 namespace build {
29 
30 
31 /// @brief simple struct defining a closed interval of residues [left, right]
32 /// where left <= right
33 struct Interval {
34 
35 
36  typedef core::Size Size;
37 
38 
39  /// @brief default constructor
40  inline
42  left( 0 ),
43  right( 0 )
44  {}
45 
46 
47  /// @brief value constructor
48  inline
50  Size const l,
51  Size const r
52  ) :
53  left( l ),
54  right( r )
55  {
56  assert( left <= right );
57  }
58 
59 
60  /// @brief copy constructor
61  inline
62  Interval( Interval const & rval ) :
63  left( rval.left ),
64  right( rval.right )
65  {}
66 
67 
68  /// @brief default destructor
69  inline
70  ~Interval() {}
71 
72 
73  /// @brief copy assignment
74  inline
75  Interval & operator =( Interval const & rval ) {
76  if ( this != &rval ) {
77  left = rval.left;
78  right = rval.right;
79  }
80  return *this;
81  }
82 
83 
84  /// @brief operator <, lexicographic ordering
85  inline
86  bool operator <( Interval const & rval ) const {
87  return (
88  ( left < rval.left ? true :
89  ( rval.left < left ? false : // left == rval.left
90  ( right < rval.right ) ) )
91  );
92  }
93 
94 
95  /// @brief operator ==
96  inline
97  bool operator ==( Interval const & rval ) const {
98  return ( left == rval.left && right == rval.right );
99  }
100 
101 
102  /// @brief length of the interval
103  inline
104  Size length() const {
105  return right - left + 1;
106  }
107 
108 
109  /// @brief do the two intervals intersect?
110  inline
111  bool intersects( Interval const & rval ) const {
112  return !( left > rval.right || rval.left > right );
113  }
114 
115 
116  /// @brief is a point contained in this interval?
117  inline
118  bool contains( Size const point ) const {
119  return ( left <= point && point <= right );
120  }
121 
122 
123  /// @brief left endpoint
125 
126 
127  /// @brief right endpoint
129 
130 
131 };
132 
133 
134 } // namespace build
135 } // namespace forge
136 } // namespace protocols
137 
138 
139 #endif /* INCLUDED_protocols_forge_build_instructions_Interval_HH */