]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/filesystem/example/path_info.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / filesystem / example / path_info.cpp
CommitLineData
7c673cae
FG
1// path_info.cpp ---------------------------------------------------------------------//
2
3// Copyright Beman Dawes 2009
4
5// Distributed under the Boost Software License, Version 1.0.
6// See http://www.boost.org/LICENSE_1_0.txt
7
8// Library home page: http://www.boost.org/libs/filesystem
9
10#include <iostream>
11#include <boost/filesystem.hpp>
1e59de90 12
7c673cae
FG
13using namespace std;
14using namespace boost::filesystem;
15
1e59de90
TL
16const char* say_what(bool b)
17{
18 return b ? "true" : "false";
19}
7c673cae
FG
20
21int main(int argc, char* argv[])
22{
1e59de90
TL
23 if (argc < 2)
24 {
25 cout << "Usage: path_info path-element [path-element...]\n"
26 "Composes a path via operator/= from one or more path-element arguments\n"
27 "Example: path_info foo/bar baz\n"
28#ifdef BOOST_POSIX_API
29 " would report info about the composed path foo/bar/baz\n";
30#else // BOOST_WINDOWS_API
31 " would report info about the composed path foo/bar\\baz\n";
32#endif
33 return 1;
34 }
7c673cae 35
1e59de90
TL
36 path p;
37 for (; argc > 1; --argc, ++argv)
38 p /= argv[1]; // compose path p from the command line arguments
7c673cae 39
1e59de90
TL
40 cout << "\ncomposed path:\n";
41 cout << " operator<<()---------: " << p << "\n";
42 cout << " make_preferred()-----: " << p.make_preferred() << "\n";
7c673cae 43
1e59de90
TL
44 cout << "\nelements:\n";
45 for (auto element : p)
46 cout << " " << element << '\n';
7c673cae 47
1e59de90
TL
48 cout << "\nobservers, native format:" << endl;
49#ifdef BOOST_POSIX_API
50 cout << " native()-------------: " << p.native() << endl;
51 cout << " c_str()--------------: " << p.c_str() << endl;
52#else // BOOST_WINDOWS_API
53 wcout << L" native()-------------: " << p.native() << endl;
54 wcout << L" c_str()--------------: " << p.c_str() << endl;
55#endif
56 cout << " string()-------------: " << p.string() << endl;
57 wcout << L" wstring()------------: " << p.wstring() << endl;
7c673cae 58
1e59de90
TL
59 cout << "\nobservers, generic format:\n";
60 cout << " generic_string()-----: " << p.generic_string() << endl;
61 wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
7c673cae 62
1e59de90
TL
63 cout << "\ndecomposition:\n";
64 cout << " root_name()----------: " << p.root_name() << '\n';
65 cout << " root_directory()-----: " << p.root_directory() << '\n';
66 cout << " root_path()----------: " << p.root_path() << '\n';
67 cout << " relative_path()------: " << p.relative_path() << '\n';
68 cout << " parent_path()--------: " << p.parent_path() << '\n';
69 cout << " filename()-----------: " << p.filename() << '\n';
70 cout << " stem()---------------: " << p.stem() << '\n';
71 cout << " extension()----------: " << p.extension() << '\n';
7c673cae 72
1e59de90
TL
73 cout << "\nquery:\n";
74 cout << " empty()--------------: " << say_what(p.empty()) << '\n';
75 cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
76 cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
77 cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
78 cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
79 cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
80 cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
81 cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
82 cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
83 cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
7c673cae 84
1e59de90 85 return 0;
7c673cae 86}