1 // Copyright (C) 2018-2019 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
6 * \brief Basic function to work with file system
18 # include <profileapi.h>
22 # include <mach/clock.h>
23 # include <mach/mach.h>
30 /// @brief File path separator
31 const char FileSeparator = '\\';
32 const char SharedLibraryExt[] = "dll";
34 const char SharedLibraryExt[] = "dylib";
35 /// @brief File path separator
36 const char FileSeparator = '/';
38 const char SharedLibraryExt[] = "so";
39 /// @brief File path separator
40 const char FileSeparator = '/';
42 /// @brief Alternative file path separator
43 const char FileSeparator2 = '/'; // second option
46 * @brief Interface function to get the size of a file
47 * @param fileName - name of the file
48 * @return size of the file
50 INFERENCE_ENGINE_API_CPP(long long) fileSize(const char *fileName);
53 * @brief Function to get the size of a file
54 * @param f - string name of the file
55 * @return size of the file
57 inline long long fileSize(const std::string &f) {
58 return fileSize(f.c_str());
62 * @brief check if file with a given filename exists
63 * @param fileName - given filename
64 * @return true is exists
66 inline bool fileExist(const char *fileName) {
67 return fileSize(fileName) >= 0;
71 * @brief check if file with a given filename exists
72 * @param fileName - string with a given filename
73 * @return true is exists
75 inline bool fileExist(const std::string &fileName) {
76 return fileExist(fileName.c_str());
80 * @brief CPP Interface function to read a file. In case of read error throws an exception
81 * @param file_name - name of the file to read
82 * @param buffer - buffer to read file to
83 * @param maxSize - maximum size in bytes to read
85 INFERENCE_ENGINE_API_CPP(void) readAllFile(const std::string &file_name, void *buffer, size_t maxSize);
88 * @brief CPP Interface function to extract path part of a filename
89 * @param filepath - filename to extract path part from
90 * @return string with path part of the filename
92 INFERENCE_ENGINE_API_CPP(std::string) folderOf(const std::string &filepath);
95 * @brief CPP Interface function to combint path with filename
96 * @param folder - path to add filename to
97 * @param file - filename to add to path
98 * @return string with combination of the path and the filename divided by file separator
100 INFERENCE_ENGINE_API_CPP(std::string) makePath(const std::string &folder, const std::string &file);
103 * @brief CPP Interface function to remove file extension
104 * @param filepath - filename with extension
105 * @return string containing filename without extension
107 INFERENCE_ENGINE_API_CPP(std::string) fileNameNoExt(const std::string &filepath);
110 * @brief CPP Interface function to extract extension from filename
111 * @param filename - name of the file which extension should be extracted
112 * @return string with extracted file extension
114 INFERENCE_ENGINE_API_CPP(std::string) fileExt(const char *filename);
117 * @brief CPP Interface function to extract extension from filename
118 * @param filename - string with the name of the file which extension should be extracted
119 * @return string with extracted file extension
121 INFERENCE_ENGINE_API_CPP(std::string) fileExt(const std::string &filename);
124 * @brief CPP Interface function to check if given filename belongs to shared library
125 * @param filename - file name to check
126 * @return true if filename is a shared library filename
128 INFERENCE_ENGINE_API_CPP(bool) isSharedLibrary(const std::string &fileName);
131 * @brief TODO: description
132 * @return TODO: please use c++11 chrono module for time operations
134 inline long long GetMicroSecTimer() {
136 static LARGE_INTEGER Frequency = { 0 };
138 if (Frequency.QuadPart == 0) QueryPerformanceFrequency(&Frequency);
139 QueryPerformanceCounter(&timer);
140 return (timer.QuadPart * 1000000) / Frequency.QuadPart;
146 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
147 clock_get_time(cclock, &mts);
148 mach_port_deallocate(mach_task_self(), cclock);
149 now.tv_sec = mts.tv_sec;
150 now.tv_nsec = mts.tv_nsec;
152 clock_gettime(CLOCK_REALTIME, &now);
154 return now.tv_sec * 1000000L + now.tv_nsec / 1000;
157 } // namespace FileUtils