HoverRace  2.0
MediaRes.h
Go to the documentation of this file.
1 
2 // MediaRes.h
3 //
4 // Copyright (c) 2014, 2016 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 <boost/filesystem/fstream.hpp>
25 
26 #include "../Util/Config.h"
27 #include "../Util/OS.h"
28 #include "../Util/Str.h"
29 
30 #include "Res.h"
31 
32 #if defined(_WIN32) && defined(HR_ENGINE_SHARED)
33 # ifdef MR_ENGINE
34 # define MR_DllDeclare __declspec( dllexport )
35 # else
36 # define MR_DllDeclare __declspec( dllimport )
37 # endif
38 #else
39 # define MR_DllDeclare
40 #endif
41 
42 namespace HoverRace {
43 namespace Display {
44 
49 template<class T>
50 class MediaRes : public Res<T>
51 {
52  using SUPER = Res<T>;
53 
54 public:
59  MediaRes(const Util::OS::path_t &path) : SUPER(), path(path),
60  id(std::string("media:") + (const char*)Util::Str::PU(path)) { }
61  virtual ~MediaRes() { }
62 
63 public:
64  std::string GetId() const override
65  {
66  return id;
67  }
68 
69  std::unique_ptr<std::istream> Open() const override
70  {
71  namespace fs = boost::filesystem;
72  auto cfg = Util::Config::GetInstance();
73  return std::unique_ptr<std::istream>(new fs::ifstream(
74  cfg->GetMediaPath() / path,
75  std::ios_base::in | std::ios_base::binary));
76  }
77 
78 private:
80  std::string id;
81 };
82 
83 } // namespace Display
84 } // namespace HoverRace
85 
86 #undef MR_DllDeclare
boost::filesystem::path path_t
Definition: OS.h:57
std::unique_ptr< std::istream > Open() const override
Open the stream for reading.
Definition: MediaRes.h:69
Definition: Str.h:39
Util::OS::path_t path
Definition: MediaRes.h:79
STL namespace.
std::string id
Definition: MediaRes.h:80
Base class for loadable resources.
Definition: Res.h:83
std::string GetId() const override
Retrieve the ID for this resource.
Definition: MediaRes.h:64
static Config * GetInstance()
Definition: Config.h:151
virtual ~MediaRes()
Definition: MediaRes.h:61
Definition: Announcement.h:24
Represents a file in the game&#39;s media directory.
Definition: MediaRes.h:50
MediaRes(const Util::OS::path_t &path)
Constructor.
Definition: MediaRes.h:59