+ string str = " " + name + "=\"" + tostr(static_cast<int>(value)) + "\"";
+ return str;
+}
+#endif
+
+
+template<>
+inline
+string const tostr(LyXAlignment const & num)
+{
+ switch(num) {
+ case LYX_ALIGN_NONE:
+ return "none";
+ case LYX_ALIGN_BLOCK:
+ return "block";
+ case LYX_ALIGN_LEFT:
+ return "left";
+ case LYX_ALIGN_CENTER:
+ return "center";
+ case LYX_ALIGN_RIGHT:
+ return "right";
+ case LYX_ALIGN_LAYOUT:
+ return "layout";
+ case LYX_ALIGN_SPECIAL:
+ return "special";
+ }
+ return string();
+}
+
+
+template<>
+inline
+string const tostr(LyXTabular::VAlignment const & num)
+{
+ switch(num) {
+ case LyXTabular::LYX_VALIGN_TOP:
+ return "top";
+ case LyXTabular::LYX_VALIGN_CENTER:
+ return "center";
+ case LyXTabular::LYX_VALIGN_BOTTOM:
+ return "bottom";
+ }
+ return string();
+}
+
+
+template<>
+inline
+string const tostr(LyXTabular::BoxType const & num)
+{
+ switch(num) {
+ case LyXTabular::BOX_NONE:
+ return "none";
+ case LyXTabular::BOX_PARBOX:
+ return "parbox";
+ case LyXTabular::BOX_MINIPAGE:
+ return "minipage";
+ }
+ return string();
+}
+
+
+void LyXTabular::Write(Buffer const * buf, ostream & os) const
+{
+ // header line
+ os << "<lyxtabular"
+ << write_attribute("version", 2)
+ << write_attribute("rows", rows_)
+ << write_attribute("columns", columns_)
+ << ">\n";
+ // global longtable options
+ os << "<features"
+ << write_attribute("rotate", tostr(rotate))
+ << write_attribute("islongtable", tostr(is_long_tabular))
+ << write_attribute("endhead", endhead)
+ << write_attribute("endfirsthead", endfirsthead)
+ << write_attribute("endfoot", endfoot)
+ << write_attribute("endlastfoot", endlastfoot)
+ << ">\n";
+ for (int j = 0; j < columns_; ++j) {
+ os << "<column"
+ << write_attribute("alignment", tostr(column_info[j].alignment))
+ << write_attribute("valignment", tostr(column_info[j].valignment))
+ << write_attribute("leftline", tostr(column_info[j].left_line))
+ << write_attribute("rightline", tostr(column_info[j].right_line))
+ << write_attribute("width",
+ VSpace(column_info[j].p_width)
+ .asLyXCommand())
+ << write_attribute("special", column_info[j].align_special)
+ << ">\n";
+ }
+ for (int i = 0; i < rows_; ++i) {
+ os << "<row"
+ << write_attribute("topline", tostr(row_info[i].top_line))
+ << write_attribute("bottomline", tostr(row_info[i].bottom_line))
+ << write_attribute("newpage", tostr(row_info[i].newpage))
+ << ">\n";
+ for (int j = 0; j < columns_; ++j) {
+ os << "<cell"
+ << write_attribute("multicolumn", cell_info[i][j].multicolumn)
+ << write_attribute("alignment", tostr(cell_info[i][j].alignment))
+ << write_attribute("valignment", tostr(cell_info[i][j].valignment))
+ << write_attribute("topline", tostr(cell_info[i][j].top_line))
+ << write_attribute("bottomline", tostr(cell_info[i][j].bottom_line))
+ << write_attribute("leftline", tostr(cell_info[i][j].left_line))
+ << write_attribute("rightline", tostr(cell_info[i][j].right_line))
+ << write_attribute("rotate", tostr(cell_info[i][j].rotate))
+ << write_attribute("usebox", tostr(cell_info[i][j].usebox))
+ << write_attribute("width", cell_info[i][j].p_width)
+ << write_attribute("special", cell_info[i][j].align_special)
+ << ">\n";
+ os << "\\begin_inset ";
+ cell_info[i][j].inset.Write(buf, os);
+ os << "\n\\end_inset \n"
+ << "</cell>\n";
+ }
+ os << "</row>\n";
+ }
+ os << "</lyxtabular>\n";
+}
+
+
+namespace {
+
+// I would have liked a fromstr template a lot better. (Lgb)
+
+inline
+bool string2type(string const str, LyXAlignment & num)
+{
+ if (str == "none")
+ num = LYX_ALIGN_NONE;
+ else if (str == "block")
+ num = LYX_ALIGN_BLOCK;
+ else if (str == "left")
+ num = LYX_ALIGN_LEFT;
+ else if (str == "center")
+ num = LYX_ALIGN_CENTER;
+ else if (str == "right")
+ num = LYX_ALIGN_RIGHT;
+ else
+ return false;
+ return true;
+}
+
+
+inline
+bool string2type(string const str, LyXTabular::VAlignment & num)
+{
+ if (str == "top")
+ num = LyXTabular::LYX_VALIGN_TOP;
+ else if (str == "center")
+ num = LyXTabular::LYX_VALIGN_CENTER;
+ else if (str == "bottom")
+ num = LyXTabular::LYX_VALIGN_BOTTOM;
+ else
+ return false;
+ return true;
+}
+
+
+inline
+bool string2type(string const str, LyXTabular::BoxType & num)
+{
+ if (str == "none")
+ num = LyXTabular::BOX_NONE;
+ else if (str == "parbox")
+ num = LyXTabular::BOX_PARBOX;
+ else if (str == "minipage")
+ num = LyXTabular::BOX_MINIPAGE;
+ else
+ return false;
+ return true;
+}
+
+
+inline
+bool string2type(string const str, bool & num)
+{
+ if (str == "true")
+ num = true;
+ else if (str == "false")
+ num = false;
+ else
+ return false;
+ return true;
+}
+
+
+bool getTokenValue(string const & str, const char * token, string & ret)
+{
+ size_t token_length = strlen(token);
+ string::size_type pos = str.find(token);
+
+ if (pos == string::npos || pos+token_length+1 >= str.length()
+ || str[pos+token_length] != '=')
+ return false;
+ ret.erase();
+ pos += token_length + 1;
+ char ch = str[pos];
+ if ((ch != '"') && (ch != '\'')) { // only read till next space
+ ret += ch;
+ ch = ' ';
+ }
+ while((pos < str.length() - 1) && (str[++pos] != ch))
+ ret += str[pos];
+
+ return true;
+}
+
+
+bool getTokenValue(string const & str, const char * token, int & num)
+{
+ string tmp;
+ if (!getTokenValue(str, token, tmp))
+ return false;
+ num = strToInt(tmp);
+ return true;
+}
+
+
+bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
+{
+ string tmp;
+ if (!getTokenValue(str, token, tmp))
+ return false;
+ return string2type(tmp, num);
+}
+
+
+bool getTokenValue(string const & str, const char * token,
+ LyXTabular::VAlignment & num)
+{
+ string tmp;
+ if (!getTokenValue(str, token, tmp))
+ return false;
+ return string2type(tmp, num);
+}