Standard Library
class OpenMode
A set of flags that says how a file is opened.
since 0.1.0-alpha.1linuxwindowswasm
Overview
The four ready-made values are std::read, std::write, std::append and std::binary. Combine them with |: std::read | std::write opens for reading and writing. File takes an OpenMode, not a plain number, so the compiler rejects a mode that is not one.
Examples
OpenMode mode = std::read | std::write;
console.writeln(mode.has(std::read));
console.writeln(mode.has(std::append));
console.writeln(mode.bits);
true
false
3
Constructors
new
new(int b)Creates a mode from its numeric flags.
You usually use the ready-made values and | instead.
Parameters
- b
- The flags as a number; see
bits.
Examples
OpenMode mode = OpenMode(6);
console.writeln(mode.has(std::write));
console.writeln(mode.has(std::append));
console.writeln(mode.has(std::read));
true
true
false
Fields
bits
int bitsThe flags as a number: read is 1, write is 2, append is 4 and binary is 8, added together.
Methods
has
has(OpenMode o) -> boolTells whether this mode includes every flag of another mode.
Parameters
- o
- The flags to look for.
Returns
true when all of the flags in o are set in this.
Examples
OpenMode mode = std::read | std::write;
console.writeln(mode.has(std::write));
console.writeln(mode.has(std::read | std::write));
console.writeln(mode.has(std::append));
true
true
false
Operators
|
Combines two modes into one that has the flags of both.
Parameters
- o
- The mode to add.
Returns
A new mode with every flag of this and of o.
Examples
OpenMode mode = std::read | std::write;
console.writeln(mode.bits);
console.writeln((std::write | std::append).bits);
3
6