blob: 70bce42b0bfc06ceae59b44c3105f915a74515ee [file] [log] [blame]
Michalis Spyroue4720822017-10-02 17:44:52 +01001/*
2 * Copyright (c) 2017 ARM Limited.
3 *
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();
46 ;
47 _filestream.open(filename, mode);
48 ARM_COMPUTE_ERROR_ON(!_filestream.good());
49 _filename = filename;
50 _mode = mode;
Michalis Spyroue4720822017-10-02 17:44:52 +010051}
52
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010053void FileHandler::close()
Michalis Spyroue4720822017-10-02 17:44:52 +010054{
Georgios Pinitas7d3d1b92017-10-12 17:34:20 +010055 _filestream.close();
56}
57
58std::fstream &FileHandler::stream()
59{
60 return _filestream;
61}
62
63std::string FileHandler::filename() const
64{
65 return _filename;
66}