monotone

monotone Mtn Source Tree

Root/src/platform-wrapped.hh

1// Copyright (C) 2006 Timothy Brownawell <tbrownaw@gmail.com>
2//
3// This program is made available under the GNU GPL version 2.0 or
4// greater. See the accompanying file COPYING for details.
5//
6// This program is distributed WITHOUT ANY WARRANTY; without even the
7// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8// PURPOSE.
9
10#ifndef __PLATFORM_WRAPPED_HH__
11#define __PLATFORM_WRAPPED_HH__
12
13#include "paths.hh"
14#include "platform.hh"
15#include "vocab.hh"
16#include "vector.hh"
17
18inline void change_current_working_dir(any_path const & to)
19{
20 change_current_working_dir(to.as_external());
21}
22
23inline path::status get_path_status(any_path const & path)
24{
25 std::string p(path.as_external());
26 return get_path_status(p.empty()?".":p);
27}
28
29inline void rename_clobberingly(any_path const & from, any_path const & to)
30{
31 rename_clobberingly(from.as_external(), to.as_external());
32}
33
34// Some generally-useful dirent consumers
35
36struct dirent_ignore : public dirent_consumer
37{
38 virtual void consume(char const *) {}
39};
40
41template <class T>
42struct fill_path_vec : public dirent_consumer
43{
44 fill_path_vec(T const & parent, std::vector<T> & v, bool isdir)
45 : parent(parent), v(v), isdir(isdir)
46 { v.clear(); }
47
48 virtual void consume(char const * s)
49 {
50 T result;
51 if (safe_compose(parent, s, result, isdir))
52 v.push_back(result);
53 }
54private:
55 T const & parent;
56 std::vector<T> & v;
57 bool isdir;
58};
59
60struct special_file_error : public dirent_consumer
61{
62 special_file_error(any_path const & p) : parent(p) {}
63 virtual void consume(char const * f)
64 {
65 any_path result;
66 if (safe_compose(parent, f, result, false))
67 E(false, origin::system,
68 F("'%s' is neither a file nor a directory") % result);
69 }
70private:
71 any_path const & parent;
72};
73
74inline void
75read_directory(any_path const & path,
76 dirent_consumer & files,
77 dirent_consumer & dirs,
78 dirent_consumer & specials)
79{
80 read_directory(path.as_external(), files, dirs, specials);
81}
82
83inline void
84read_directory(any_path const & path,
85 dirent_consumer & files,
86 dirent_consumer & dirs)
87{
88 special_file_error sfe(path);
89 read_directory(path.as_external(), files, dirs, sfe);
90}
91
92#endif
93
94// Local Variables:
95// mode: C++
96// fill-column: 76
97// c-file-style: "gnu"
98// indent-tabs-mode: nil
99// End:
100// vim: et:sw=2:sts=2:ts=2:cino=>2s,{s,\:s,+s,t0,g0,^-2,e-2,n-2,p2s,(0,=s:

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status