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.
21 namespace support { class FileName; }
24 * Utility to copy a file of a specified format from one place to another.
25 * This base class simply invokes the command support::copy().
32 /** Copy file @c from to @c to.
33 * This version should be used to copy files from the original
34 * location to the temporary directory, since @c to and @c latex
35 * would be equal in this case.
36 * \returns true if successful.
39 copy(support::FileName const & from, support::FileName const & to,
40 unsigned long int mode = (unsigned long int)-1) const;
42 /** Copy file @c from to @c to.
43 * \see SpecialisedMover::SpecialisedMover() for an explanation of
45 * This version should be used to copy files from the temporary
46 * directory to the export location, since @c to and @c latex may
47 * not be equal in this case.
48 * \returns true if successful.
51 copy(support::FileName const & from, support::FileName const & to,
52 std::string const & latex,
53 unsigned long int mode = (unsigned long int)-1) const
55 return do_copy(from, to, latex, mode);
58 /** Rename file @c from as @c to.
59 * This version should be used to move files from the original
60 * location to the temporary directory, since @c to and @c latex
61 * would be equal in this case.
62 * \returns true if successful.
65 rename(support::FileName const & from, support::FileName const & to) const;
67 /** Rename file @c from as @c to.
68 * \see SpecialisedMover::SpecialisedMover() for an explanation of
70 * This version should be used to move files from the temporary
71 * directory to the export location, since @c to and @c latex may
72 * not be equal in this case.
73 * \returns true if successful.
76 rename(support::FileName const & from, support::FileName const & to,
77 std::string const & latex) const
79 return do_rename(from, to, latex);
84 do_copy(support::FileName const & from, support::FileName const & to,
85 std::string const &, unsigned long int mode) const;
88 do_rename(support::FileName const & from, support::FileName const & to,
89 std::string const &) const;
94 * Specialisation of the Mover concept that uses an external command
97 * For example, an XFig .fig file can contain references to external
98 * picture files. If such a reference has a relative path, then the
99 * copied .fig file will require a transformation of the picture file
100 * reference if it is to be found by XFig.
102 class SpecialisedMover : public Mover
105 SpecialisedMover() {}
107 /** @c command should be of the form
109 * python $$s/scripts/fig_copy.py $$i $$o $$l
111 * where $$s is a placeholder for the lyx support directory,
112 * $$i is a placeholder for the name of the file to be moved,
113 * $$o is a placeholder for the name of the file after moving,
114 * $$l is a placeholder for the name of the file after moving,
115 * suitable as argument to a latex include command. This is
116 * either an absolute filename or relative to the master
118 * $$o and $$l can only differ if the file is copied from the
119 * temporary directory to the export location. If it is copied
120 * from the original location to the temporary directory, they
121 * are the same, so $$l may be ommitted in this case.
123 SpecialisedMover(std::string const & command)
124 : command_(command) {}
126 /// The template used to launch the external command.
127 std::string const & command() const { return command_; }
131 do_copy(support::FileName const & from, support::FileName const & to,
132 std::string const & latex, unsigned long int mode) const;
135 do_rename(support::FileName const & from, support::FileName const & to,
136 std::string const & latex) const;
138 std::string command_;
143 * Manage the store of (Mover)s.
148 /** Register a specialised @c command to be used to copy a file
151 void set(std::string const & fmt, std::string const & command);
153 /// @c returns the Mover registered for format @c fmt.
154 Mover const & operator()(std::string const & fmt) const;
156 /** @returns the command template if @c fmt 'finds' a
157 * SpecialisedMover. Otherwise, returns an empty string.
159 std::string const command(std::string const & fmt) const;
162 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
165 typedef SpecialsMap::const_iterator iterator;
166 iterator begin() const { return specials_.begin(); }
167 iterator end() const { return specials_.end(); }
171 SpecialsMap specials_;
175 extern Movers movers;
176 extern Movers system_movers;