blob: a6c16fff4b317c0de998e2bb7f3acb3ff74b0b71 [file] [log] [blame]
Michalis Spyroue4720822017-10-02 17:44:52 +01001/*
Giorgio Arena6e9d0e02020-01-03 15:02:04 +00002 * 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 <string>
Michalis Spyroue4720822017-10-02 17:44:52 +010025
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010026#include "arm_compute/core/utils/io/FileHandler.h"
Michalis Spyroue4720822017-10-02 17:44:52 +010027
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010028#include "arm_compute/core/Error.h"
29#include "support/ToolchainSupport.h"
Michalis Spyroue4720822017-10-02 17:44:52 +010030
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010031using namespace arm_compute::io;
32
33FileHandler::FileHandler()
34 : _filestream(), _filename(" "), _mode()
Michalis Spyroue4720822017-10-02 17:44:52 +010035{
36}
37
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010038FileHandler::~FileHandler()
Michalis Spyroue4720822017-10-02 17:44:52 +010039{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010040 close();
Michalis Spyroue4720822017-10-02 17:44:52 +010041}
42
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010043void FileHandler::open(const std::string &filename, std::ios_base::openmode mode)
Michalis Spyroue4720822017-10-02 17:44:52 +010044{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010045 close();
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010046 _filestream.open(filename, mode);
47 ARM_COMPUTE_ERROR_ON(!_filestream.good());
48 _filename = filename;
49 _mode = mode;
Michalis Spyroue4720822017-10-02 17:44:52 +010050}
51
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010052void FileHandler::close()
Michalis Spyroue4720822017-10-02 17:44:52 +010053{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010054 _filestream.close();
55}
56
57std::fstream &FileHandler::stream()
58{
59 return _filestream;
60}
61
62std::string FileHandler::filename() const
63{
64 return _filename;
65}