Nebula
Loading...
Searching...
No Matches
path.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
15#include "core/types.h"
16#include "util/string.h"
17#include "util/stringatom.h"
18#include "util/dictionary.h"
19#include "io/uri.h"
20
21//------------------------------------------------------------------------------
22namespace IO
23{
24
25class Path
26{
27public:
28
29 // TODO: switch from using a string for the type, and use an enum
37
39 Path();
41 ~Path();
42
44 Path(const Path& path);
45
47 static Path Parse(const Util::String& serialized);
49 static Path Folder(const Util::String& folder);
53 static Path FolderAndFile(const char* type, const Util::String& folderAndFile);
55 static Path File(const Util::String& folder, const Util::String& file, const Util::String& type);
57 static Path File(const Util::String& folder, const Util::String& file, const char* type);
58
60 void Clear();
62 bool IsEmpty() const;
64 bool IsFolder() const;
66 bool IsFile() const;
67
69 const Util::String AsString() const;
70
72 bool operator==(const Path& path) const;
74 bool operator<(const Path& path) const;
76 bool operator>(const Path& path) const;
78 Path operator/(const char* folder) const;
80 Path operator/(const Util::String& folder) const;
82 Path operator/(const Path& folder) const;
84 IO::URI WorkURI(const char* workFolder) const;
86 IO::URI WorkURI(const Util::String& workFolder) const;
88 IO::URI ExportURI() const;
89
91 void SetFolder(const Util::String& folder);
93 void ClearFolder();
95 void SetFile(const Util::String& file, const Util::String& type);
97 void ClearFile();
98
100 const Util::String& GetFolderAndFile() const;
102 const Util::String& GetFile() const;
104 const Util::String& GetFolder() const;
106 const Util::String& GetType() const;
107
112
114 static void AddExportMapping(const Util::StringAtom& ns, const Util::StringAtom& extension);
116 static void AddWorkMapping(const Util::StringAtom& ns, const Util::StringAtom& extension);
118 static void SetWorkRoot(const Util::StringAtom& root);
119
122
123private:
125 void Build();
126
127 bool isFile;
131
133};
134
135
136//------------------------------------------------------------------------------
139inline void
141{
143 Path::ExportExtensions.Add(ns, extension);
144}
145
146//------------------------------------------------------------------------------
149inline void
151{
153 Path::WorkExtensions.Add(ns, extension);
154}
155
156//------------------------------------------------------------------------------
159inline void
161{
162 Path::WorkRoot = root;
163}
164
165} // namespace IO
166
167//------------------------------------------------------------------------------
170IO::Path operator""_path(const char* c, std::size_t s);
A path is an abstraction around file paths.
Definition path.h:26
Util::String folderAndFile
Definition path.h:132
const Util::String & GetFolderAndFile() const
Get folder and file path.
Definition path.cc:383
~Path()
Destructor.
Definition path.cc:38
Util::String GetExportFile() const
Get file with export extension.
Definition path.cc:432
void SetFolder(const Util::String &folder)
Set the folder.
Definition path.cc:340
const Util::String & GetFolder() const
Get folder.
Definition path.cc:401
bool IsFolder() const
Returns true if the path is a folder.
Definition path.cc:177
void ClearFile()
Clear the file.
Definition path.cc:372
Util::String GetWorkFile() const
Get file with work extension.
Definition path.cc:419
bool IsFile() const
Returns true if the path is a file.
Definition path.cc:186
static Util::StringAtom WorkRoot
Definition path.h:121
static Path Parse(const Util::String &serialized)
Parse from serialized Path.
Definition path.cc:58
Util::String type
Definition path.h:130
const Util::String & GetFile() const
Get file.
Definition path.cc:392
void Clear()
Clear the path.
Definition path.cc:156
bool IsEmpty() const
Returns true if path is empty.
Definition path.cc:168
static void SetWorkRoot(const Util::StringAtom &root)
Set the work folder.
Definition path.h:160
bool operator==(const Path &path) const
Comparison test.
Definition path.cc:204
const Util::String & GetType() const
Get type.
Definition path.cc:410
bool operator>(const Path &path) const
Greater test.
Definition path.cc:222
void Build()
Build fileAndFolder.
Definition path.cc:443
FileTypes
Definition path.h:31
@ Texture
Definition path.h:32
@ Material
Definition path.h:34
@ Mesh
Definition path.h:35
@ Model
Definition path.h:33
bool isFile
Definition path.h:127
Util::String file
Definition path.h:129
IO::URI WorkURI(const char *workFolder) const
Convert to a URI seated in the provided folder.
Definition path.cc:277
Util::String folder
Definition path.h:128
static Path Folder(const Util::String &folder)
Construct from folder.
Definition path.cc:78
static void AddWorkMapping(const Util::StringAtom &ns, const Util::StringAtom &extension)
Add a work binding using namespace -> file extension to use with WorkURI.
Definition path.h:150
static Util::Dictionary< Util::StringAtom, Util::StringAtom > ExportExtensions
Definition path.h:120
Path()
Constructor.
Definition path.cc:30
Path operator/(const char *folder) const
Append to folder path.
Definition path.cc:231
void ClearFolder()
Clear the folder.
Definition path.cc:350
const Util::String AsString() const
Serialize to string.
Definition path.cc:195
bool operator<(const Path &path) const
Less test.
Definition path.cc:213
static Path FolderAndFile(const Util::String &type, const Util::String &folderAndFile)
Construct from file type, combined folder and file path.
Definition path.cc:92
IO::URI ExportURI() const
Convert to a folder in 'export'.
Definition path.cc:327
static Path File(const Util::String &folder, const Util::String &file, const Util::String &type)
Construct from folder, file and type separately.
Definition path.cc:124
static void AddExportMapping(const Util::StringAtom &ns, const Util::StringAtom &extension)
Add an export binding using namespace -> file extension to use with ExportURI.
Definition path.h:140
static Util::Dictionary< Util::StringAtom, Util::StringAtom > WorkExtensions
Definition path.h:120
void SetFile(const Util::String &file, const Util::String &type)
Set the file.
Definition path.cc:360
An URI object can split a Uniform Resource Identifier string into its components or build a string fr...
Definition uri.h:67
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:35
A StringAtom.
Definition stringatom.h:22
Nebula's universal string class.
Definition string.h:50
#define n_assert(exp)
Definition debug.h:58
Instances of wrapped stream classes.
Definition multiplayerfeatureunit.cc:324
static const int InvalidIndex
Definition types.h:47