1/*
2 * Copyright 2010-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License").
5 * You may not use this file except in compliance with the License.
6 * A copy of the License is located at
7 *
8 * http://aws.amazon.com/apache2.0
9 *
10 * or in the "license" file accompanying this file. This file is distributed
11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12 * express or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15#pragma once
16#include <aws/core/Core_EXPORTS.h>
17#include <aws/core/utils/memory/stl/AWSStreamFwd.h>
18#include <aws/core/utils/memory/stl/AWSString.h>
19#include <aws/core/platform/FileSystem.h>
20
21#include <fstream>
22
23namespace Aws
24{
25 namespace Utils
26 {
27
28 class AWS_CORE_API FStreamWithFileName : public Aws::FStream
29 {
30 public:
31 FStreamWithFileName(const Aws::String& fileName, std::ios_base::openmode openFlags) :
32 Aws::FStream(fileName.c_str(), openFlags), m_fileName(fileName) {}
33
34 virtual ~FStreamWithFileName() = default;
35
36 const Aws::String& GetFileName() const { return m_fileName; }
37 protected:
38 Aws::String m_fileName;
39 };
40
41 /**
42 * Provides a fstream around a temporary file. This file gets deleted upon an instance of this class's destructor being called.
43 */
44 class AWS_CORE_API TempFile : public Aws::Utils::FStreamWithFileName
45 {
46 public:
47 /**
48 * Creates a temporary file with [prefix][temp name][suffix] e.g.
49 * prefix of "foo" and suffix of ".bar" will generate foo[some random string].bar
50 */
51 TempFile(const char* prefix, const char* suffix, std::ios_base::openmode openFlags);
52 /**
53 * Creates a temporary file with [prefix][temp name] e.g.
54 * prefix of "foo" will generate foo[some random string]
55 */
56 TempFile(const char* prefix, std::ios_base::openmode openFlags);
57 /**
58 * Creates a temporary file with a randome string for the name.
59 */
60 TempFile(std::ios_base::openmode openFlags);
61
62 ~TempFile();
63 };
64
65 class AWS_CORE_API PathUtils
66 {
67 public:
68
69 /**
70 * Get file name from it's full path, e.g get "file1" from "/path/to/file1.ext"; get "file2" from "/path/to/file2"
71 */
72 static Aws::String GetFileNameFromPathWithoutExt(const Aws::String& path);
73
74 /**
75 * Get file name from it's full path, e.g get "file1.ext" from "/path/to/file1.ext"; get "file2" from "/path/to/file2"
76 */
77 static Aws::String GetFileNameFromPathWithExt(const Aws::String& path);
78 };
79 }
80}
81