Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
[submodule "Extern/Bandit"]
path = Extern/Bandit
url = https://github.com/banditcpp/bandit.git
[submodule "Extern/efsw"]
path = Extern/efsw
url = https://github.com/SpartanJ/efsw.git
4 changes: 0 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ file(GLOB_RECURSE PIPE_SOURCE_FILES CONFIGURE_DEPENDS Src/*.cpp Src/*.h)
target_sources(Pipe PRIVATE ${PIPE_SOURCE_FILES})
target_compile_definitions(Pipe PRIVATE NOMINMAX)

target_link_libraries(Pipe PRIVATE
efsw
)

if(PIPE_ENABLE_ALLOCATION_STACKS)
target_compile_definitions(Pipe PUBLIC P_ENABLE_ALLOCATION_STACKS=0)
endif()
Expand Down
6 changes: 0 additions & 6 deletions Extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,3 @@ set(EFSW_INSTALL OFF)

add_library(Bandit INTERFACE)
target_include_directories(Bandit INTERFACE Bandit)

add_subdirectory(efsw)
pipe_target_disable_all_warnings(efsw PRIVATE)
if(PLATFORM_LINUX)
set_target_properties(efsw PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
1 change: 0 additions & 1 deletion Extern/efsw
Submodule efsw deleted from 6fb0c9
10 changes: 5 additions & 5 deletions Include/Pipe/Core/MacPlatform.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ namespace p
} // namespace p

#if __is_target_arch(arm64) || __is_target_arch(arm64e)
#define P_PLATFORM_MAC_ARM64 1
#define P_PLATFORM_MAC_X86 0
#define P_PLATFORM_MACOS_ARM64 1
#define P_PLATFORM_MACOS_X86 0
#else
#define P_PLATFORM_MAC_ARM64 0
#define P_PLATFORM_MAC_X86 1
#define P_PLATFORM_MACOS_ARM64 0
#define P_PLATFORM_MACOS_X86 1
#endif


Expand All @@ -46,7 +46,7 @@ namespace p
#endif
#define P_NOINLINE __attribute__((noinline))

#if P_PLATFORM_MAC_X86
#if P_PLATFORM_MACOS_X86
#define P_PLATFORM_BREAK() __asm__("int $3")
#else
#define P_PLATFORM_BREAK() __builtin_debugtrap()
Expand Down
32 changes: 26 additions & 6 deletions Include/Pipe/Core/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
#pragma once

#ifndef P_PLATFORM_WINDOWS
#if defined(_WIN64)
#define P_PLATFORM_WINDOWS 1
#elif defined(_WIN32)
#if defined(_WIN64) || defined(_WIN32)
#define P_PLATFORM_WINDOWS 1
#else
#define P_PLATFORM_WINDOWS 0
Expand All @@ -14,18 +12,40 @@
#ifndef P_PLATFORM_LINUX
#if defined(__linux__)
#define P_PLATFORM_LINUX 1
#if defined(__ANDROID__) || defined(ANDROID)
#define P_PLATFORM_ANDROID 1
#endif
#else
#define P_PLATFORM_LINUX 0
#define P_PLATFORM_ANDROID 0
#endif
#endif
#ifndef P_PLATFORM_MACOS
#if defined(__APPLE__)
#define P_PLATFORM_MACOS 1
#ifndef P_PLATFORM_APPLE
#if defined(__APPLE__) || defined(__APPLE_CC__)
#define P_PLATFORM_APPLE 1
#if defined(__IPHONE__) || (defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE) \
|| (defined(TARGET_IPHONE_SIMULATOR) && TARGET_IPHONE_SIMULATOR)
#define P_PLATFORM_IOS 1
#define P_PLATFORM_MACOS 0
#else
#define P_PLATFORM_MACOS 1
#define P_PLATFORM_IOS 0
#endif
#else
#define P_PLATFORM_APPLE 0
#define P_PLATFORM_MACOS 0
#define P_PLATFORM_IOS 0
#endif
#endif

#ifndef P_PLATFORM_BSD
#if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) \
|| defined(__DragonFly__)
#define P_PLATFORM_BSD 1
#else
#define P_PLATFORM_BSD 0
#endif
#endif

#if P_PLATFORM_WINDOWS
#include "Pipe/Core/WindowsPlatform.h"
Expand Down
2 changes: 1 addition & 1 deletion Include/Pipe/Files/LambdaFileIterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace p
{
template<typename Iterator = PathIterator>
template<typename Iterator = DirectoryIterator>
class LambdaFileIterator
{
public:
Expand Down
72 changes: 72 additions & 0 deletions Include/Pipe/Files/Paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ namespace p

PIPE_API bool IsAbsolutePath(StringView path);
PIPE_API bool IsRelativePath(StringView path);
PIPE_API bool IsRemotePath(StringView path);
PIPE_API bool Exists(StringView path);

PIPE_API String JoinPaths(StringView base, StringView relative);
Expand Down Expand Up @@ -108,4 +109,75 @@ namespace p

PIPE_API String ToString(const Path& path);
PIPE_API std::filesystem::path ToSTDPath(StringView pathStr);


#pragma region PathIterator
struct PathIterator
{
enum class State : u8
{
// Zero is a special sentinel value used by default constructed iterators.
BeforeBegin,
InRootName,
InRootDir,
InFilenames,
InTrailingSep,
AtEnd
};

const StringView path;
StringView rawEntry;
State state;

private:
PathIterator(StringView path, State state) noexcept : path(path), state(state) {}

public:
PathIterator(StringView path, StringView entry, State state)
: path(path), rawEntry(entry), state(state)
{
// S cannot be '0' or BeforeBegin.
}

static PathIterator CreateBegin(StringView p) noexcept;
static PathIterator CreateEnd(StringView p) noexcept;

const TChar* Peek() const noexcept;
void Increment() noexcept;
void Decrement() noexcept;

/** @return a view with the "preferred representation" of the current
* element. For example trailing separators are represented as a '.'
*/
StringView operator*() const noexcept;
explicit operator bool() const noexcept;
PathIterator& operator++() noexcept;
PathIterator& operator--() noexcept;
bool operator==(const PathIterator& other) const noexcept;
bool operator!=(const PathIterator& other) const noexcept;

bool AtEnd() const noexcept;
bool InRootDir() const noexcept;
bool InRootName() const noexcept;
bool InRootPath() const noexcept;

private:
void MakeState(State newState, const TChar* start, const TChar* end) noexcept;
void MakeState(State newState) noexcept;
const TChar* GetAfterBack() const noexcept;
const TChar* GetBeforeFront() const noexcept;
/// @return a pointer to the first character after the currently lexed element.
const TChar* GetNextTokenStartPos() const noexcept;
/// @return a pointer to the first character in the currently lexed element.
const TChar* GetCurrentTokenStartPos() const noexcept;
// Consume all consecutive separators
const TChar* ConsumeAllSeparators(const TChar* p, const TChar* end) const noexcept;
// Consume exactly N separators, or return nullptr.
const TChar* ConsumeNSeparators(const TChar* p, const TChar* end, int N) const noexcept;
const TChar* ConsumeName(const TChar* p, const TChar* end) const noexcept;
const TChar* ConsumeDriveLetter(const TChar* p, const TChar* end) const noexcept;
const TChar* ConsumeNetworkRoot(const TChar* p, const TChar* end) const noexcept;
const TChar* ConsumeRootName(const TChar* p, const TChar* end) const noexcept;
};
#pragma endregion PathIterator
} // namespace p
10 changes: 5 additions & 5 deletions Include/Pipe/Files/STDFileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ namespace p
using Path = fs::path;
using PathView = TStringView<Path::value_type>;

using PathIterator = fs::directory_iterator;
using RecursivePathIterator = fs::recursive_directory_iterator;
using SpaceInfo = fs::space_info;
using DirectoryIterator = fs::directory_iterator;
using RecursiveDirectoryIterator = fs::recursive_directory_iterator;
using SpaceInfo = fs::space_info;

enum class CopyOptions
{
Expand Down Expand Up @@ -54,6 +54,6 @@ namespace p
PIPE_API void Read(p::Reader& ct, p::Path& value);
PIPE_API void Write(p::Writer& ct, const p::Path& value);

PIPE_API PathIterator CreatePathIterator(StringView path);
PIPE_API RecursivePathIterator CreateRecursivePathIterator(StringView path);
PIPE_API DirectoryIterator CreateDirIterator(StringView path);
PIPE_API RecursiveDirectoryIterator CreateRecursiveDirIterator(StringView path);
} // namespace p
78 changes: 44 additions & 34 deletions Include/PipeFiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,6 @@

namespace p
{
#pragma region FileWatch
enum class FileWatchAction : p::u8
{
Add = 1,
Delete = 2,
Modified = 3,
Moved = 4
};

using FileListenerId = long;
using FileWatchCallback = std::function<void(
StringView path, StringView filename, FileWatchAction action, StringView oldFilename)>;

struct PIPE_API FileWatcher
{
private:
OwnPtr fileWatcher;
p::TArray<TOwnPtr<struct FileWatchListener>> listeners;

public:
FileWatcher();
~FileWatcher();
FileWatcher(const FileWatcher& other) = delete;
FileWatcher& operator=(const FileWatcher& other) = delete;

FileListenerId ListenPath(StringView path, bool recursive, FileWatchCallback callback);
void StopListening(FileListenerId id);
void Reset();

void StartAsync();
};
#pragma endregion FileWatch


#pragma region FileDialogs
using DialogFileFilter = TPair<StringView, StringView>;

Expand Down Expand Up @@ -104,4 +70,48 @@ namespace p
},
bool alwaysShowDefaultPath = false, bool confirmOverwrite = false);
#pragma endregion FileDialogs


#pragma region FileWatch
enum class FileWatchAction : p::u8
{
Add = 1,
Delete = 2,
Modified = 3,
Moved = 4
};

using FileWatchId = i32;
using FileWatchCallback = std::function<void(FileWatchId id, StringView path,
StringView filename, FileWatchAction action, StringView oldFilename)>;

struct PIPE_API FileWatcher
{
public:
/** Should recursive watchers follow symbolic links? Default: false */
bool followsSymlinks = false;

/** Allow symlinks to watch recursively out of the pointed directory. Default: false.
* 'followsSymlinks' must be enabled.
* E.g: A symlink from '/home/folder' to '/'. With 'followsSymlinks=false' only '/home' and
* deeper are allowed. Set to false it will prevent infinite recursion.
*/
bool allowsOutOfScopeLinks = false;

private:
OwnPtr fileWatcher;

public:
FileWatcher(bool useGeneric = false);
~FileWatcher();
FileWatcher(const FileWatcher& other) = delete;
FileWatcher& operator=(const FileWatcher& other) = delete;

FileWatchId ListenPath(StringView path, bool recursive, FileWatchCallback callback);
void StopListening(FileWatchId id);
void Reset();

void StartWatchingAsync();
};
#pragma endregion FileWatch
}; // namespace p
Loading