Fixposition SDK 0.0.0-heads/main-0-g7b59b93
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
path.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: File and path utilities
12 *
13 * @page FPSDK_COMMON_PATH File and path utilities
14 *
15 * **API**: fpsdk_common/path.hpp and fpsdk::common::path
16 *
17 */
18#ifndef __FPSDK_COMMON_PATH_HPP__
19#define __FPSDK_COMMON_PATH_HPP__
20
21/* LIBC/STL */
22#include <iostream>
23#include <memory>
24#include <string>
25#include <vector>
26
27/* EXTERNAL */
28
29/* PACKAGE */
30
31namespace fpsdk {
32namespace common {
33/**
34 * @brief File and path utilities
35 */
36namespace path {
37/* ****************************************************************************************************************** */
38
39/**
40 * @brief Check if path exists
41 *
42 * @param[in] path Path (file or directory) to check
43 *
44 * @returns true if path exists, false otherwise
45 */
46bool PathExists(const std::string& path);
47
48/**
49 * @brief Get file size
50 *
51 * @param[in] path Path to file
52 *
53 * @returns the size of the file in bytes, 0 is only valid if file is readable
54 */
55std::size_t FileSize(const std::string& path);
56
57/**
58 * @brief Output file handle
59 */
61{
62 public:
63 OutputFile();
65
66 /**
67 * @brief Open output file for writing
68 *
69 * @param[in] path The path / filename, can end in ".gz" for compressed output
70 *
71 * @returns true on success, failure otherwise
72 */
73 bool Open(const std::string& path);
74
75 /**
76 * @brief Close output file
77 */
78 void Close();
79
80 /**
81 * @brief Write data to file
82 *
83 * @param[in] data The data to be written
84 *
85 * @returns true on success, false otherwise
86 */
87 bool Write(const std::vector<uint8_t>& data);
88 /**
89 * @brief Write data to file
90 *
91 * @param[in] data The data to be written
92 * @param[in] size The size of the data to be written
93 *
94 * @returns true on success, false otherwise
95 */
96 bool Write(const uint8_t* data, const std::size_t size);
97
98 private:
99 std::string path_; //!< File path
100 std::unique_ptr<std::ostream> fh_; //!< File handle
101};
102
103/* ****************************************************************************************************************** */
104} // namespace path
105} // namespace common
106} // namespace fpsdk
107#endif // __FPSDK_COMMON_PATH_HPP__
Output file handle.
Definition path.hpp:61
bool Open(const std::string &path)
Open output file for writing.
bool Write(const uint8_t *data, const std::size_t size)
Write data to file.
void Close()
Close output file.
bool Write(const std::vector< uint8_t > &data)
Write data to file.
bool PathExists(const std::string &path)
Check if path exists.
std::size_t FileSize(const std::string &path)
Get file size.
Fixposition SDK.
Definition fpsdk_doc.hpp:20