]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/filesystem/example/path_info.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / filesystem / example / path_info.cpp
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>
12 using namespace std;
13 using namespace boost::filesystem;
14
15 const char * say_what(bool b) { return b ? "true" : "false"; }
16
17 int main(int argc, char* argv[])
18 {
19 if (argc < 2)
20 {
21 cout << "Usage: path_info path-element [path-element...]\n"
22 "Composes a path via operator/= from one or more path-element arguments\n"
23 "Example: path_info foo/bar baz\n"
24 # ifdef BOOST_POSIX_API
25 " would report info about the composed path foo/bar/baz\n";
26 # else // BOOST_WINDOWS_API
27 " would report info about the composed path foo/bar\\baz\n";
28 # endif
29 return 1;
30 }
31
32 path p;
33 for (; argc > 1; --argc, ++argv)
34 p /= argv[1]; // compose path p from the command line arguments
35
36 cout << "\ncomposed path:\n";
37 cout << " operator<<()---------: " << p << "\n";
38 cout << " make_preferred()-----: " << p.make_preferred() << "\n";
39
40 cout << "\nelements:\n";
41 for (auto element : p)
42 cout << " " << element << '\n';
43
44 cout << "\nobservers, native format:" << endl;
45 # ifdef BOOST_POSIX_API
46 cout << " native()-------------: " << p.native() << endl;
47 cout << " c_str()--------------: " << p.c_str() << endl;
48 # else // BOOST_WINDOWS_API
49 wcout << L" native()-------------: " << p.native() << endl;
50 wcout << L" c_str()--------------: " << p.c_str() << endl;
51 # endif
52 cout << " string()-------------: " << p.string() << endl;
53 wcout << L" wstring()------------: " << p.wstring() << endl;
54
55 cout << "\nobservers, generic format:\n";
56 cout << " generic_string()-----: " << p.generic_string() << endl;
57 wcout << L" generic_wstring()----: " << p.generic_wstring() << endl;
58
59 cout << "\ndecomposition:\n";
60 cout << " root_name()----------: " << p.root_name() << '\n';
61 cout << " root_directory()-----: " << p.root_directory() << '\n';
62 cout << " root_path()----------: " << p.root_path() << '\n';
63 cout << " relative_path()------: " << p.relative_path() << '\n';
64 cout << " parent_path()--------: " << p.parent_path() << '\n';
65 cout << " filename()-----------: " << p.filename() << '\n';
66 cout << " stem()---------------: " << p.stem() << '\n';
67 cout << " extension()----------: " << p.extension() << '\n';
68
69 cout << "\nquery:\n";
70 cout << " empty()--------------: " << say_what(p.empty()) << '\n';
71 cout << " is_absolute()--------: " << say_what(p.is_absolute()) << '\n';
72 cout << " has_root_name()------: " << say_what(p.has_root_name()) << '\n';
73 cout << " has_root_directory()-: " << say_what(p.has_root_directory()) << '\n';
74 cout << " has_root_path()------: " << say_what(p.has_root_path()) << '\n';
75 cout << " has_relative_path()--: " << say_what(p.has_relative_path()) << '\n';
76 cout << " has_parent_path()----: " << say_what(p.has_parent_path()) << '\n';
77 cout << " has_filename()-------: " << say_what(p.has_filename()) << '\n';
78 cout << " has_stem()-----------: " << say_what(p.has_stem()) << '\n';
79 cout << " has_extension()------: " << say_what(p.has_extension()) << '\n';
80
81 return 0;
82 }