blob: d1064932380d664937e0237e5de9d194bc61dabd [file] [log] [blame]
Michalis Spyroue4720822017-10-02 17:44:52 +01001/*
Michele Di Giorgiod9eaf612020-07-08 11:12:57 +01002 * Copyright (c) 2017-2020 Arm Limited.
Michalis Spyroue4720822017-10-02 17:44:52 +01003 *
4 * SPDX-License-Identifier: MIT
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to
8 * deal in the Software without restriction, including without limitation the
9 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
10 * sell copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010024#include "arm_compute/core/utils/io/FileHandler.h"
Michalis Spyroue4720822017-10-02 17:44:52 +010025
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010026#include "arm_compute/core/Error.h"
Michalis Spyroue4720822017-10-02 17:44:52 +010027
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010028#include <string>
29
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010030using namespace arm_compute::io;
31
Felix Thomasmathibalanafd38f02023-09-27 17:46:17 +010032FileHandler::FileHandler() : _filestream(), _filename(" "), _mode()
Michalis Spyroue4720822017-10-02 17:44:52 +010033{
34}
35
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010036FileHandler::~FileHandler()
Michalis Spyroue4720822017-10-02 17:44:52 +010037{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010038 close();
Michalis Spyroue4720822017-10-02 17:44:52 +010039}
40
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010041void FileHandler::open(const std::string &filename, std::ios_base::openmode mode)
Michalis Spyroue4720822017-10-02 17:44:52 +010042{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010043 close();
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010044 _filestream.open(filename, mode);
45 ARM_COMPUTE_ERROR_ON(!_filestream.good());
46 _filename = filename;
47 _mode = mode;
Michalis Spyroue4720822017-10-02 17:44:52 +010048}
49
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010050void FileHandler::close()
Michalis Spyroue4720822017-10-02 17:44:52 +010051{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010052 _filestream.close();
53}
54
55std::fstream &FileHandler::stream()
56{
57 return _filestream;
58}
59
60std::string FileHandler::filename() const
61{
62 return _filename;
63}