OmniSciDB  72c90bc290
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
File.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
23 #pragma once
24 
25 #define DATA_FILE_EXT ".data"
26 
27 #include <cstdint>
28 #include <cstdio>
29 #include <iostream>
30 #include <string>
31 
32 #include "Shared/types.h"
33 
34 namespace File_Namespace {
35 
36 constexpr auto kLegacyDataFileExtension{".mapd"};
37 
38 std::string get_data_file_path(const std::string& base_path,
39  int file_id,
40  size_t page_size);
41 
42 std::string get_legacy_data_file_path(const std::string& new_data_file_path);
43 
44 std::pair<FILE*, std::string> create(const std::string& basePath,
45  const int fileId,
46  const size_t pageSize,
47  const size_t npages);
48 
57 FILE* create(const std::string& full_path, const size_t requested_file_size);
58 
65 FILE* open(int file_id);
66 FILE* open(const std::string& path);
67 
73 void close(FILE* f);
74 
82 bool removeFile(const std::string& basePath, const std::string& filename);
83 
94 size_t read(FILE* f,
95  const size_t offset,
96  const size_t size,
97  int8_t* buf,
98  const std::string& file_path);
99 
110 size_t write(FILE* f, const size_t offset, const size_t size, const int8_t* buf);
111 
121 size_t append(FILE* f, const size_t size, const int8_t* buf);
122 
133 size_t readPage(FILE* f,
134  const size_t pageSize,
135  const size_t pageNum,
136  int8_t* buf,
137  const std::string& file_path);
138 
149 size_t writePage(FILE* f, const size_t pageSize, const size_t pageNum, int8_t* buf);
150 
160 size_t appendPage(FILE* f, const size_t pageSize, int8_t* buf);
161 
167 size_t fileSize(FILE* f);
168 
173 void renameForDelete(const std::string directoryName);
174 
175 } // namespace File_Namespace
size_t appendPage(FILE *f, const size_t pageSize, int8_t *buf)
Appends a page from buf to the file.
Definition: File.cpp:193
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:158
std::string get_legacy_data_file_path(const std::string &new_data_file_path)
Definition: File.cpp:49
size_t writePage(FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf)
Writes a page from buf to the file.
Definition: File.cpp:180
std::pair< FILE *, std::string > create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:55
size_t write(FILE *f, const size_t offset, const size_t size, const int8_t *buf)
Writes the specified number of bytes to the offset position in file f from buf.
Definition: File.cpp:143
bool removeFile(const std::string &base_path, const std::string &filename)
Deletes the file pointed to by the FILE pointer.
Definition: File.cpp:120
size_t read(FILE *f, const size_t offset, const size_t size, int8_t *buf, const std::string &file_path)
Reads the specified number of bytes from the offset position in file f into buf.
Definition: File.cpp:125
size_t fileSize(FILE *f)
Returns the size of the specified file.
Definition: File.cpp:198
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
FILE * open(int file_id)
Opens the file with the given id; fatal crash on error.
Definition: File.cpp:100
void close(FILE *f)
Closes the file pointed to by the FILE pointer.
Definition: File.cpp:114
std::string get_data_file_path(const std::string &base_path, int file_id, size_t page_size)
Definition: File.cpp:42
void renameForDelete(const std::string directoryName)
Renames a directory to DELETE_ME_&lt;EPOCH&gt;_&lt;oldname&gt;.
Definition: File.cpp:210
constexpr auto kLegacyDataFileExtension
Definition: File.h:36
size_t readPage(FILE *f, const size_t pageSize, const size_t pageNum, int8_t *buf, const std::string &file_path)
Reads the specified page from the file f into buf.
Definition: File.cpp:162