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) const;
41 /** Rename file @c from as @c to.
42 * This version should be used to move files from the original
43 * location to the temporary directory, since @c to and @c latex
44 * would be equal in this case.
45 * \returns true if successful.
48 rename(support::FileName const & from, support::FileName const & to) const;
50 /** Rename file @c from as @c to.
51 * \see SpecialisedMover::SpecialisedMover() for an explanation of
53 * This version should be used to move files from the temporary
54 * directory to the export location, since @c to and @c latex may
55 * not be equal in this case.
56 * \returns true if successful.
59 rename(support::FileName const & from, support::FileName const & to,
60 std::string const & latex) const
62 return do_rename(from, to, latex);
67 do_rename(support::FileName const & from, support::FileName const & to,
68 std::string const &) const;
73 * Specialisation of the Mover concept that uses an external command
76 * For example, an Xfig .fig file can contain references to external
77 * picture files. If such a reference has a relative path, then the
78 * copied .fig file will require a transformation of the picture file
79 * reference if it is to be found by Xfig.
81 class SpecialisedMover : public Mover
86 virtual ~SpecialisedMover() {}
88 /** @c command should be of the form
90 * python $$s/scripts/fig_copy.py $$i $$o $$l
92 * where $$s is a placeholder for the lyx support directory,
93 * $$i is a placeholder for the name of the file to be moved,
94 * $$o is a placeholder for the name of the file after moving,
95 * $$l is a placeholder for the name of the file after moving,
96 * suitable as argument to a latex include command. This is
97 * either an absolute filename or relative to the master
99 * $$o and $$l can only differ if the file is copied from the
100 * temporary directory to the export location. If it is copied
101 * from the original location to the temporary directory, they
102 * are the same, so $$l may be ommitted in this case.
104 SpecialisedMover(std::string const & command)
105 : command_(command) {}
107 /// The template used to launch the external command.
108 std::string const & command() const { return command_; }
112 do_copy(support::FileName const & from, support::FileName const & to,
113 std::string const & latex) const;
116 do_rename(support::FileName const & from, support::FileName const & to,
117 std::string const & latex) const;
119 std::string command_;
124 * Manage the store of (Mover)s.
129 /** Register a specialised @c command to be used to copy a file
132 void set(std::string const & fmt, std::string const & command);
134 /// @c returns the Mover registered for format @c fmt.
135 Mover const & operator()(std::string const & fmt) const;
137 /** @returns the command template if @c fmt 'finds' a
138 * SpecialisedMover. Otherwise, returns an empty string.
140 std::string const command(std::string const & fmt) const;
143 typedef std::map<std::string, SpecialisedMover> SpecialsMap;
146 typedef SpecialsMap::const_iterator const_iterator;
147 const_iterator begin() const { return specials_.begin(); }
148 const_iterator end() const { return specials_.end(); }
152 SpecialsMap specials_;
156 extern Movers & theMovers();
157 /// @c returns the Mover registered for format @c fmt.
158 extern Mover const & getMover(std::string const & fmt);
159 /** Register a specialised @c command to be used to copy a file
162 extern void setMover(std::string const & fmt, std::string const & command);
163 extern Movers & theSystemMovers();