HoverRace  2.0
Bundle.h
Go to the documentation of this file.
1 
2 // Bundle.h
3 //
4 // Copyright (c) 2010, 2015 Michael Imamura.
5 //
6 // Licensed under GrokkSoft HoverRace SourceCode License v1.0(the "License");
7 // you may not use this file except in compliance with the License.
8 //
9 // A copy of the license should have been attached to the package from which
10 // you have taken this file. If you can not find the license you can not use
11 // this file.
12 //
13 //
14 // The author makes no representations about the suitability of
15 // this software for any purpose. It is provided "as is" "AS IS",
16 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
17 // implied.
18 //
19 // See the License for the specific language governing permissions
20 // and limitations under the License.
21 
22 #pragma once
23 
24 #include "../Util/OS.h"
25 
26 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
27 # ifdef MR_ENGINE
28 # define MR_DllDeclare __declspec( dllexport )
29 # else
30 # define MR_DllDeclare __declspec( dllimport )
31 # endif
32 #else
33 # define MR_DllDeclare
34 #endif
35 
36 namespace HoverRace {
37 namespace Parcel {
38 
39 class RecordFile;
40 
46 {
47 public:
48  Bundle(const Util::OS::path_t &dir,
49  std::shared_ptr<Bundle> subBundle = std::shared_ptr<Bundle>());
50  virtual ~Bundle() { }
51 
52  virtual std::shared_ptr<RecordFile> OpenParcel(
53  const std::string &name, bool writing = false) const;
54 
55 private:
57  public std::iterator<std::input_iterator_tag, Util::OS::dirEnt_t>
58  {
59  public:
60  Iterator();
61  Iterator(const Bundle *bundle);
62 
63  public:
64  bool operator==(const Iterator &other) const
65  {
66  return (bundle == other.bundle) && (iter == other.iter);
67  }
68  bool operator!=(const Iterator &other) const
69  {
70  return (bundle != other.bundle) || (iter != other.iter);
71  }
72 
73  Util::OS::dirEnt_t &operator*() const { return *iter; }
74  Util::OS::dirEnt_t *operator->() const { return &*iter; }
75 
76  Iterator &operator++();
77  Iterator operator++(int);
78 
79  private:
80  void FindNextValidBundle();
81 
82  private:
83  const Bundle *bundle;
85  static const Util::OS::dirIter_t END;
86  };
87 public:
88  using iterator = Iterator;
91 
92  iterator begin() { return iterator(this); }
93  iterator end() { return END; }
94  const_iterator begin() const { return iterator(this); }
95  const_iterator end() const { return END; }
96  const_iterator cbegin() const { return iterator(this); }
97  const_iterator cend() const { return END; }
98 
99 private:
101  std::shared_ptr<Bundle> subBundle;
102  static const iterator END;
103 };
104 
105 } // namespace Parcel
106 } // namespace HoverRace
107 
108 #undef MR_DllDeclare
static const Util::OS::dirIter_t END
Definition: Bundle.h:85
static const iterator END
Definition: Bundle.h:102
const_iterator end() const
Definition: Bundle.h:95
boost::filesystem::path path_t
Definition: OS.h:57
Util::OS::dirEnt_t & operator*() const
Definition: Bundle.h:73
const_iterator begin() const
Definition: Bundle.h:94
boost::filesystem::directory_iterator dirIter_t
Definition: OS.h:58
A source of parcels.
Definition: Bundle.h:45
virtual ~Bundle()
Definition: Bundle.h:50
const_iterator cbegin() const
Definition: Bundle.h:96
Util::OS::dirEnt_t * operator->() const
Definition: Bundle.h:74
bool operator!=(const Iterator &other) const
Definition: Bundle.h:68
std::shared_ptr< Bundle > subBundle
Definition: Bundle.h:101
Util::OS::path_t dir
Definition: Bundle.h:100
boost::filesystem::directory_entry dirEnt_t
Definition: OS.h:59
Util::OS::dirEnt_t value_type
Definition: Bundle.h:90
Util::OS::dirIter_t iter
Definition: Bundle.h:84
iterator begin()
Definition: Bundle.h:92
const_iterator cend() const
Definition: Bundle.h:97
Definition: Announcement.h:24
bool operator==(const Iterator &other) const
Definition: Bundle.h:64
iterator end()
Definition: Bundle.h:93
const Bundle * bundle
Definition: Bundle.h:83
#define MR_DllDeclare
Definition: Bundle.h:33