Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef CSV_PLOC_HXX
21 : #define CSV_PLOC_HXX
22 :
23 : // USED SERVICES
24 : #include <cosv/string.hxx>
25 : #include <cosv/plocroot.hxx>
26 : #include <cosv/dirchain.hxx>
27 : #include <cosv/tpl/dyn.hxx>
28 : #include <cosv/csv_ostream.hxx>
29 :
30 :
31 :
32 :
33 : namespace csv
34 : {
35 : class bostream;
36 :
37 : namespace ploc
38 : {
39 : class Root;
40 :
41 :
42 : /** Represents a path in the file system.
43 :
44 : The path can be relative or absolute and in Unix- or Windows-syntax.
45 : */
46 : class Path
47 : {
48 : public:
49 :
50 : // LIFECYCLE
51 : explicit Path(
52 : const char * i_sPath = ".", /// Dirs have to be ended with a '\\ or '/'.
53 : bool i_bPathIsAlwaysDir = false, /// This overrides a missing Delimiter at the end of the i_sPath, if true.
54 : const char * i_sDelimiter = Delimiter() );
55 : Path(
56 : const Path & i_rPath );
57 : ~Path();
58 : // OPERATORS
59 : Path & operator=(
60 : const Path & i_rPath );
61 : // OPERATIONS
62 : void Set(
63 : const char * i_sPath,
64 : bool i_bPathIsAlwaysDir = false,
65 : const char * i_sDelimiter = Delimiter() );
66 : void SetFile( // If there is already a file, that is exchanged.
67 : const String & i_sName );
68 : // INQUIRY
69 28113 : const Root & RootDir() const { return *pRoot; }
70 : const DirectoryChain &
71 0 : DirChain() const { return aPath; }
72 : const String & File() const { return sFile; }
73 : bool IsValid() const;
74 12211 : bool IsDirectory() const { return sFile.length() == 0; }
75 : bool IsFile() const { return sFile.length() > 0; }
76 :
77 : /// Directories have a delimiter at the end, files not.
78 : void Get(
79 : bostream & o_rPath ) const;
80 : // ACCESS
81 237 : DirectoryChain & DirChain() { return aPath; }
82 :
83 : private:
84 : Dyn<Root> pRoot;
85 : DirectoryChain aPath;
86 : String sFile;
87 : };
88 :
89 :
90 :
91 :
92 : } // namespace ploc
93 : } // namespace csv
94 :
95 : /// Directories produce a delimiter at the end, files not.
96 : inline csv::bostream &
97 20281 : operator<<( csv::bostream & o_rOut,
98 : const csv::ploc::Path & i_rPath )
99 : {
100 20281 : i_rPath.Get(o_rOut);
101 20281 : return o_rOut;
102 : }
103 :
104 : #endif
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|