Omnidome
Fulldome Mapping Software Toolkit
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Location.h
Go to the documentation of this file.
1 /* Copyright (c) 2014-2016 "Omnidome" by cr8tr
2  * Dome Mapping Projection Software (http://omnido.me).
3  * Omnidome was created by Michael Winkelmann aka Wilston Oreo (@WilstonOreo)
4  *
5  * This file is part of Omnidome.
6  *
7  * Omnidome is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU Affero General Public License for more details.
16  * You should have received a copy of the GNU Affero General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef OMNI_MEDIA_INTERFACE_H_
21 #define OMNI_MEDIA_INTERFACE_H_
22 
23 #include <QString>
24 #include <QDataStream>
25 #include <omni/exception.h>
26 
27 namespace omni {
28  namespace media {
29  /// Base interface for loading external media files
30  class Location {
31  public:
32  Location();
33  Location(QString const&);
34 
35  template<typename MEDIA>
36  void reload(MEDIA& _media) {
37  load(path_,_media);
38  }
39 
40  /// Load media from file
41  template<typename MEDIA>
42  void load(QString const& _path, MEDIA& _media) {
43  setPath(_path);
44  _media.load(_path);
45  }
46 
47  bool exists() const;
48  static bool exists(QString const&);
49 
50  uint64_t fileSize() const;
51  QString const& path() const;
52  void setPath(QString const&);
53 
54  /// Relocate media by searching directories, with optional directory hint
55  void relocate(QString const& _directoryHint = QString());
56 
57  private:
58  qint64 fileSize_ = 0;
59  QString path_;
60  };
61 
62  namespace exception {
63  /// Exception which is thrown when a media does not exist in location
64  class NotExisting : public Error {
65  public:
67 
68  NotExisting(Location& _location) :
69  location_(_location) {}
70 
71  inline QString message() const throw() {
72  QString _msg("Location %1 does not exist!");
73  _msg = _msg.arg(location_.path());
74  return _msg;
75  }
76 
77  private:
79  };
80  }
81 
82  }
83 }
84 
85 QDataStream& operator>>(QDataStream&,
87 QDataStream& operator<<(QDataStream&,
88  omni::media::Location const&);
89 
90 
91 #endif /* OMNI_MEDIA_INTERFACE_H_ */
void relocate(QString const &_directoryHint=QString())
Relocate media by searching directories, with optional directory hint.
Definition: Location.cpp:46
void reload(MEDIA &_media)
Definition: Location.h:36
Exception which is thrown when a media does not exist in location.
Definition: Location.h:64
void setPath(QString const &)
Definition: Location.cpp:55
QDataStream & operator>>(QDataStream &, omni::media::Location &)
Definition: Location.cpp:67
void load(QString const &_path, MEDIA &_media)
Load media from file.
Definition: Location.h:42
QString const & path() const
Definition: Location.cpp:42
QString path_
Definition: Location.h:59
#define OMNI_EXCEPTION(EXCEPTION)
Definition: exception.h:55
Location & location_
Definition: Location.h:78
QDataStream & operator<<(QDataStream &, omni::media::Location const &)
Definition: Location.cpp:75
Location()
Definition: Location.cpp:27
Base interface for loading external media files.
Definition: Location.h:30
bool exists() const
Definition: Location.cpp:33
uint64_t fileSize() const
QString message() const
Definition: Location.h:71
qint64 fileSize_
Definition: Location.h:58