On 07/09/2011 3:37 PM, Richard Heck wrote:
On 09/07/2011 08:36 AM, Julien Rioux wrote:
On 07/09/2011 2:09 PM, Julien Rioux wrote:
On 06/09/2011 2:57 AM, Richard Heck wrote:
@@ -90,9 +90,13 @@ bool operator<(Format const& a, Format const& b)
Format::Format(string const& n, string const& e, string const& p,
string const& s, string const& v, string const& ed,
int flags)
- : name_(n), extension_(e), prettyname_(p), shortcut_(s), viewer_(v),
+ : name_(n), extensions_(e), prettyname_(p), shortcut_(s), viewer_(v),
editor_(ed), flags_(flags)
-{}
+{
+ extension_list_ = getVectorFromString(e, ",");
+ if (extension_list_.empty())
+ extension_list_.push_back("");
+}
I'd probably have to look more closely at the patch, but are we sure
this is needed? We can always check for empty()-ness when we need to do so.
I push an empty string to prevent extension_list_ from being empty,
because in Format.h we have
- std::string const & extension() const { return extension_; }
+ std::string const & extension() const { return extension_list_[0]; }
and extension_list_[0] would be an invalid address otherwise.
+bool Format::hasExtension(string const& e) const
+{
+ if (extension().empty())
+ return false;
+ std::vector<string>::const_iterator it = extension_list_.begin();
+ std::vector<string>::const_iterator end = extension_list_.end();
+ for (; it != end; ++it) {
+ if ((*it) == e)
+ return true;
+ }
+ return false;
+}
This can be done more easily (and faster) with the std::find algorithm.
Just:
return find(extension_list_.begin(), extension_list_.end(), e) !=
extension_list_.end();
Nice.
+void Format::setExtensions(string const& e)
+{
+ extensions_ = e;
+ extension_list_ = getVectorFromString(e, ",");
+ if (extension_list_.empty())
+ extension_list_.push_back("");
+}
It probably doesn't matter very much, but you could avoid maintaining
both extensions_ and extension_list_ and just create the former from the
latter when you need it. We're in effect caching the result of one
direction of the conversion between these two. The vector-->string
direction, I'm guessing, is pretty cheap, so no need. The splitting
business seems expensive. Hence the idea to use that one as the basis.
Anyway, good work. This will be very helpful.
Richard
It's useful to keep the whole string since it is used in LyXRC.cpp,
GuiView.cpp, GuiPrefs.cpp, etc.
The string->vector conversion will happen once on startup and once each
time the setting is changed in the gui. Which one are you concerned about?
The use of the vector form is constrained to Format.cpp, so perhaps
there is some magic to be done that the string->vector conversion would
occur only once it's necessary.
Julien