tdf#130857 qt weld: Support "Java Start Parameters" dialog
[LibreOffice.git] / codemaker / source / netmaker / csharpfile.hxx
blob6bdc430552dc0eff16a7b049c09551d756879f11
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #pragma once
12 #include <filesystem>
13 #include <fstream>
14 #include <string>
15 #include <string_view>
17 class CSharpFile
19 public:
20 CSharpFile(std::string_view directory, std::string_view typeName)
21 : m_filePath(createFilePath(directory, typeName))
25 public:
26 std::string getPath() const { return m_filePath.string(); }
28 void openFile()
30 std::filesystem::create_directories(m_filePath.parent_path());
31 m_fileStream.open(m_filePath, std::fstream::out | std::fstream::trunc);
32 m_indentLevel = 0;
34 void closeFile() { m_fileStream.close(); }
36 CSharpFile& beginBlock()
38 beginLine();
39 append("{");
40 endLine();
41 ++m_indentLevel;
42 return *this;
44 CSharpFile& endBlock()
46 --m_indentLevel;
47 beginLine();
48 append("}");
49 endLine();
50 return *this;
53 CSharpFile& beginLine()
55 for (int i = 0; i < m_indentLevel; i++)
57 m_fileStream << " ";
59 return *this;
62 CSharpFile& extraIndent()
64 m_fileStream << " ";
65 return *this;
68 CSharpFile& append(std::string_view item)
70 m_fileStream << item;
71 return *this;
74 CSharpFile& append(std::u16string_view item)
76 m_fileStream << u2b(item);
77 return *this;
80 CSharpFile& endLine()
82 m_fileStream << '\n';
83 return *this;
86 private:
87 static std::filesystem::path createFilePath(std::string_view dir, std::string_view type)
89 std::string subdir(type);
90 for (char& c : subdir)
91 if (c == '.')
92 c = '/';
94 std::filesystem::path path(dir);
95 path /= subdir + ".cs";
96 return path;
99 private:
100 std::filesystem::path m_filePath;
101 std::ofstream m_fileStream;
102 int m_indentLevel = 0;
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */