Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review anonymous file mode enum. #902

Open
1uc opened this issue Dec 19, 2023 · 0 comments
Open

Review anonymous file mode enum. #902

1uc opened this issue Dec 19, 2023 · 0 comments
Labels
v3 Anything that needs to be resolved before `v3`.

Comments

@1uc
Copy link
Collaborator

1uc commented Dec 19, 2023

enum : unsigned {
/// Open flag: Read only access
ReadOnly = 0x00u,
/// Open flag: Read Write access
ReadWrite = 0x01u,
/// Open flag: Truncate a file if already existing
Truncate = 0x02u,
/// Open flag: Open will fail if file already exist
Excl = 0x04u,
/// Open flag: Open in debug mode
Debug = 0x08u,
/// Open flag: Create non existing file
Create = 0x10u,
/// Derived open flag: common write mode (=ReadWrite|Create|Truncate)
Overwrite = Truncate,
/// Derived open flag: Opens RW or exclusively creates
OpenOrCreate = ReadWrite | Create
};

and then here:

explicit File(const std::string& filename,
unsigned openFlags = ReadOnly,
const FileAccessProps& fileAccessProps = FileAccessProps::Default());

isn't particularly type safe. One option is:

class File {
  enum class FileMode {
    ReadOnly,
  };

  static constexpr ReadOnly = FileMode::ReadOnly;

  
};

and a lot of boiler plate to allow it to work properly as a bitset. Or use:

using FileMode = std::bitset<?>;

class File {
  static constexpr FileMode ReadOnly = {...};
};
@1uc 1uc added the v3 Anything that needs to be resolved before `v3`. label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v3 Anything that needs to be resolved before `v3`.
Projects
None yet
Development

No branches or pull requests

1 participant