Files
bx/include/bx/filepath.h
Branimir Karadžić c04c499aee Added home dir lookup.
2017-11-15 20:19:57 -08:00

92 lines
1.5 KiB
C++

/*
* Copyright 2010-2017 Branimir Karadzic. All rights reserved.
* License: https://github.com/bkaradzic/bx#license-bsd-2-clause
*/
#ifndef BX_FILEPATH_H_HEADER_GUARD
#define BX_FILEPATH_H_HEADER_GUARD
#include "string.h"
namespace bx
{
const int32_t kMaxFilePath = 1024;
///
struct Dir
{
enum Enum ///
{
Temp,
Home,
Count
};
};
/// FilePath parser and helper.
///
/// /abv/gd/555/333/pod.mac
/// ppppppppppppppppbbbeeee
/// ^ ^ ^
/// +-path base-+ +-ext
/// ^^^^^^^
/// +-filename
///
class FilePath
{
public:
///
FilePath();
///
FilePath(Dir::Enum _dir);
///
FilePath(const char* _str);
///
FilePath(const StringView& _str);
///
FilePath& operator=(const StringView& _rhs);
///
void set(Dir::Enum _dir);
///
void set(const StringView& _str);
///
void join(const StringView& _str);
///
const char* get() const;
/// If path is `/abv/gd/555/333/pod.mac` returns `/abv/gd/555/333/`.
///
const StringView getPath() const;
/// If path is `/abv/gd/555/333/pod.mac` returns `pod.mac`.
///
const StringView getFileName() const;
/// If path is `/abv/gd/555/333/pod.mac` returns `pod`.
///
const StringView getBaseName() const;
/// If path is `/abv/gd/555/333/pod.mac` returns `.mac`.
///
const StringView getExt() const;
///
bool isAbsolute() const;
private:
char m_filePath[kMaxFilePath];
};
} // namespace bx
#endif // BX_FILEPATH_H_HEADER_GUARD