Consider the case where there is not any layout name.
[lyx.git] / src / mover.h
blob0b74e00fdc068206f0298f4edadf025c33d82cd7
1 // -*- C++ -*-
2 /**
3 * \file mover.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Angus Leeming
9 * Full author contact details are available in file CREDITS.
12 #ifndef MOVER_H
13 #define MOVER_H
15 #include <map>
16 #include <string>
18 /**
19 * Utility to copy a file of a specified format from one place to another.
20 * This base class simply invokes the command support::copy().
22 class Mover
24 public:
25 virtual ~Mover() {}
27 /** Copy file @c from to @c to.
28 * This version should be used to copy files from the original
29 * location to the temporary directory, since @c to and @c latex
30 * would be equal in this case.
31 * \returns true if successful.
33 bool
34 copy(std::string const & from, std::string const & to) const
36 return do_copy(from, to, to);
39 /** Copy file @c from to @c to.
40 * \see SpecialisedMover::SpecialisedMover() for an explanation of
41 * @c latex.
42 * This version should be used to copy files from the temporary
43 * directory to the export location, since @c to and @c latex may
44 * not be equal in this case.
45 * \returns true if successful.
47 bool
48 copy(std::string const & from, std::string const & to,
49 std::string const & latex) const
51 return do_copy(from, to, latex);
54 /** Rename file @c from as @c to.
55 * This version should be used to move files from the original
56 * location to the temporary directory, since @c to and @c latex
57 * would be equal in this case.
58 * \returns true if successful.
60 bool
61 rename(std::string const & from, std::string const & to) const
63 return do_rename(from, to, to);
66 /** Rename file @c from as @c to.
67 * \see SpecialisedMover::SpecialisedMover() for an explanation of
68 * @c latex.
69 * This version should be used to move files from the temporary
70 * directory to the export location, since @c to and @c latex may
71 * not be equal in this case.
72 * \returns true if successful.
74 bool
75 rename(std::string const & from, std::string const & to,
76 std::string const & latex) const
78 return do_rename(from, to, latex);
81 protected:
82 virtual bool
83 do_copy(std::string const & from, std::string const & to,
84 std::string const &) const;
86 virtual bool
87 do_rename(std::string const & from, std::string const & to,
88 std::string const &) const;
92 /**
93 * Specialisation of the Mover concept that uses an external command
94 * to copy a file.
96 * For example, an XFig .fig file can contain references to external
97 * picture files. If such a reference has a relative path, then the
98 * copied .fig file will require a transformation of the picture file
99 * reference if it is to be found by XFig.
101 class SpecialisedMover : public Mover
103 public:
104 SpecialisedMover() {}
106 /** @c command should be of the form
107 * <code>
108 * sh $$s/scripts/fig_copy.sh $$i $$o $$l
109 * </code>
110 * where $$s is a placeholder for the lyx support directory,
111 * $$i is a placeholder for the name of the file to be moved,
112 * $$o is a placeholder for the name of the file after moving,
113 * $$l is a placeholder for the name of the file after moving,
114 * suitable as argument to a latex include command. This is
115 * either an absolute filename or relative to the master
116 * document.
117 * $$o and $$l can only differ if the file is copied from the
118 * temporary directory to the export location. If it is copied
119 * from the original location to the temporary directory, they
120 * are the same, so $$l may be ommitted in this case.
122 SpecialisedMover(std::string const & command)
123 : command_(command) {}
125 /// The template used to launch the external command.
126 std::string const & command() const { return command_; }
128 private:
129 virtual bool
130 do_copy(std::string const & from, std::string const & to,
131 std::string const & latex) const;
133 virtual bool
134 do_rename(std::string const & from, std::string const & to,
135 std::string const & latex) const;
137 std::string command_;
142 * Manage the store of (Mover)s.
144 class Movers
146 public:
147 /** Register a specialised @c command to be used to copy a file
148 * of format @c fmt.
150 void set(std::string const & fmt, std::string const & command);
152 /// @c returns the Mover registered for format @c fmt.
153 Mover const & operator()(std::string const & fmt) const;
155 /** @returns the command template if @c fmt 'finds' a
156 * SpecialisedMover. Otherwise, returns an empty string.
158 std::string const command(std::string const & fmt) const;
160 private:
161 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
163 public:
164 typedef SpecialsMap::const_iterator iterator;
165 iterator begin() const { return specials_.begin(); }
166 iterator end() const { return specials_.end(); }
168 private:
169 Mover default_;
170 SpecialsMap specials_;
174 extern Movers movers;
175 extern Movers system_movers;
177 #endif // MOVER_H