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{
142 n_assert(Path::ExportExtensions.FindIndex(ns) == InvalidIndex);
143 Path::ExportExtensions.Add(ns, extension);
144}
145
146//------------------------------------------------------------------------------
149inline void
151{
152 n_assert(Path::WorkExtensions.FindIndex(ns) == InvalidIndex);
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:390
Util::String GetExportFile() const
Get file with export extension.
Definition path.cc:439
void SetFolder(const Util::String &folder)
Set the folder.
Definition path.cc:346
const Util::String & GetFolder() const
Get folder.
Definition path.cc:408
bool IsFolder() const
Returns true if the path is a folder.
Definition path.cc:183
void ClearFile()
Clear the file.
Definition path.cc:379
Util::String GetWorkFile() const
Get file with work extension.
Definition path.cc:426
bool IsFile() const
Returns true if the path is a file.
Definition path.cc:192
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:399
void Clear()
Clear the path.
Definition path.cc:162
bool IsEmpty() const
Returns true if path is empty.
Definition path.cc:174
static void SetWorkRoot(const Util::StringAtom &root)
Set the work folder.
Definition path.h:160
const Util::String & GetType() const
Get type.
Definition path.cc:417
void Build()
Build fileAndFolder.
Definition path.cc:450
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:283
Util::String folder
Definition path.h:128
static Path Folder(const Util::String &folder)
Construct from folder.
Definition path.cc:80
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
void ClearFolder()
Clear the folder.
Definition path.cc:356
const Util::String AsString() const
Serialize to string.
Definition path.cc:201
static Path FolderAndFile(const Util::String &type, const Util::String &folderAndFile)
Construct from file type, combined folder and file path.
Definition path.cc:94
IO::URI ExportURI() const
Convert to a folder in 'export'.
Definition path.cc:333
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:128
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:366
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
half operator/(half one, half two)
Definition half.h:132
bool operator==(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:106
bool operator>(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:124
bool operator<(const PosixFileTime &a, const PosixFileTime &b)
Definition posixfiletime.h:136