Google OR-Tools v9.11
a fast and portable software suite for combinatorial optimization
Loading...
Searching...
No Matches
File Class Reference

#include <file.h>

Public Member Functions

size_t Read (void *buff, size_t size)
 Reads "size" bytes to buff from file, buff should be pre-allocated.
 
void ReadOrDie (void *buff, size_t size)
 
char * ReadLine (char *output, uint64_t max_length)
 
int64_t ReadToString (std::string *line, uint64_t max_length)
 
size_t Write (const void *buff, size_t size)
 Writes "size" bytes of buff to file, buff should be pre-allocated.
 
void WriteOrDie (const void *buff, size_t size)
 
size_t WriteString (absl::string_view str)
 Writes a string to file.
 
bool WriteLine (absl::string_view line)
 Writes a string to file and append a "\n".
 
bool Close ()
 Closes the file.
 
absl::Status Close (int flags)
 Deletes "this" on closing.
 
bool Flush ()
 Flushes buffer.
 
size_t Size ()
 Returns file size.
 
absl::string_view filename () const
 Returns the file name.
 
bool Open () const
 

Static Public Member Functions

static FileOpen (absl::string_view filename, absl::string_view mode)
 
static FileOpenOrDie (absl::string_view filename, absl::string_view mode)
 
static void Init ()
 Inits internal data structures.
 
static bool Delete (absl::string_view filename)
 Deletes a file.
 
static bool Exists (absl::string_view filename)
 Tests if a file exists.
 

Detailed Description

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. This file defines some IO interfaces for compatibility with Google IO specifications.

Definition at line 30 of file file.h.

Member Function Documentation

◆ Close() [1/2]

bool File::Close ( )

Closes the file.

Deletes "this" on closing.

Definition at line 66 of file file.cc.

◆ Close() [2/2]

absl::Status File::Close ( int flags)

Deletes "this" on closing.

Definition at line 81 of file file.cc.

◆ Delete()

bool File::Delete ( absl::string_view filename)
static

Deletes a file.

Definition at line 47 of file file.cc.

◆ Exists()

bool File::Exists ( absl::string_view filename)
static

Tests if a file exists.

Definition at line 52 of file file.cc.

◆ filename()

absl::string_view File::filename ( ) const

Returns the file name.

Definition at line 163 of file file.cc.

◆ Flush()

bool File::Flush ( )

Flushes buffer.

Definition at line 63 of file file.cc.

◆ Init()

void File::Init ( )
static

Inits internal data structures.

Definition at line 167 of file file.cc.

◆ Open() [1/2]

bool File::Open ( ) const

Definition at line 165 of file file.cc.

◆ Open() [2/2]

File * File::Open ( absl::string_view filename,
absl::string_view mode )
static

Opens file "name" with flags specified by "mode". Flags are defined by fopen(), that is "r", "r+", "w", "w+". "a", and "a+". The caller should free the File after closing it by passing the returned pointer to delete.

Definition at line 116 of file file.cc.

◆ OpenOrDie()

File * File::OpenOrDie ( absl::string_view filename,
absl::string_view mode )
static

Opens file "name" with flags specified by "mode". If open failed, program will exit. The caller should free the File after closing it by passing the returned pointer to delete.

Definition at line 110 of file file.cc.

◆ Read()

size_t File::Read ( void * buff,
size_t size )

Reads "size" bytes to buff from file, buff should be pre-allocated.

Definition at line 101 of file file.cc.

◆ ReadLine()

char * File::ReadLine ( char * output,
uint64_t max_length )

Reads a line from file to a string. Each line must be no more than max_length bytes.

Definition at line 126 of file file.cc.

◆ ReadOrDie()

void File::ReadOrDie ( void * buff,
size_t size )

Reads "size" bytes to buff from file, buff should be pre-allocated. If read failed, program will exit.

Definition at line 97 of file file.cc.

◆ ReadToString()

int64_t File::ReadToString ( std::string * line,
uint64_t max_length )

Reads the whole file to a string, with a maximum length of 'max_length'. Returns the number of bytes read.

Definition at line 130 of file file.cc.

◆ Size()

size_t File::Size ( )

Returns file size.

Definition at line 57 of file file.cc.

◆ Write()

size_t File::Write ( const void * buff,
size_t size )

Writes "size" bytes of buff to file, buff should be pre-allocated.

Definition at line 106 of file file.cc.

◆ WriteLine()

bool File::WriteLine ( absl::string_view line)

Writes a string to file and append a "\n".

Definition at line 158 of file file.cc.

◆ WriteOrDie()

void File::WriteOrDie ( const void * buff,
size_t size )

Writes "size" bytes of buff to file, buff should be pre-allocated. If write failed, program will exit.

Definition at line 103 of file file.cc.

◆ WriteString()

size_t File::WriteString ( absl::string_view str)

Writes a string to file.

Definition at line 154 of file file.cc.


The documentation for this class was generated from the following files: