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

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 29 of file file.h.

#include <file.h>

Public Member Functions

 File (absl::string_view name)
virtual ~File ()=default
virtual size_t Read (void *buf, size_t size)=0
 Reads "size" bytes to buf from file, buff should be pre-allocated.
virtual size_t Write (const void *buf, size_t size)=0
 Writes "size" bytes of buf to file, buff should be pre-allocated.
virtual absl::Status Close (int flags)=0
 Closes the file and delete the underlying FILE* descriptor.
virtual bool Flush ()=0
 Flushes buffer.
virtual size_t Size ()=0
 Returns file size.
virtual bool Open () const =0
 Returns whether the file is currently open.
int64_t ReadToString (std::string *line, uint64_t max_length)
size_t WriteString (absl::string_view str)
 Writes a string to file.
absl::string_view filename () const
 Returns the file name.

Static Public Member Functions

static FileOpen (absl::string_view file_name, absl::string_view mode)
static FileOpenOrDie (absl::string_view file_name, absl::string_view mode)
static void Init ()
 Inits internal data structures.

Protected Attributes

std::string name_

Constructor & Destructor Documentation

◆ File()

File::File ( absl::string_view name)
explicit

Definition at line 251 of file file.cc.

◆ ~File()

virtual File::~File ( )
virtualdefault

Member Function Documentation

◆ Close()

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

Closes the file and delete the underlying FILE* descriptor.

◆ filename()

absl::string_view File::filename ( ) const

Returns the file name.

Definition at line 322 of file file.cc.

◆ Flush()

virtual bool File::Flush ( )
pure virtual

Flushes buffer.

◆ Init()

void File::Init ( )
static

Inits internal data structures.

Definition at line 324 of file file.cc.

◆ Open() [1/2]

virtual bool File::Open ( ) const
pure virtual

Returns whether the file is currently open.

◆ Open() [2/2]

File * File::Open ( absl::string_view file_name,
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 call Close() to free the File after closing it.

never reach

Definition at line 259 of file file.cc.

◆ OpenOrDie()

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

Opens file "name" with flags specified by "mode". If open failed, program will exit. The caller should call Close() to free the File after closing it.

Definition at line 253 of file file.cc.

◆ Read()

virtual size_t File::Read ( void * buf,
size_t size )
pure virtual

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

◆ 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 294 of file file.cc.

◆ Size()

virtual size_t File::Size ( )
pure virtual

Returns file size.

◆ Write()

virtual size_t File::Write ( const void * buf,
size_t size )
pure virtual

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

◆ WriteString()

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

Writes a string to file.

Definition at line 318 of file file.cc.

Member Data Documentation

◆ name_

std::string File::name_
protected

Definition at line 78 of file file.h.


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