row_vector::iterator rit = row_info.begin() + row;
row_info.insert(rit, rowstruct());
+ // now set the values of the row before
+ row_info[row] = row_info[row+1];
#if 0
cell_vvector::iterator cit = cell_info.begin() + row;
int const column = column_of_cell(cell);
column_vector::iterator cit = column_info.begin() + column + 1;
column_info.insert(cit, columnstruct());
+ // set the column values of the column before
+ column_info[column+1] = column_info[column];
for (int i = 0; i < rows_; ++i) {
for (int j = 0; j <= column; ++j) {
#endif
-string const type2string(LyXAlignment num)
+template<>
+inline
+string const tostr(LyXAlignment const & num)
{
switch(num) {
case LYX_ALIGN_NONE:
}
-string const type2string(LyXTabular::VAlignment num)
+template<>
+inline
+string const tostr(LyXTabular::VAlignment const & num)
{
switch(num) {
case LyXTabular::LYX_VALIGN_TOP:
}
-string const type2string(LyXTabular::BoxType num)
+template<>
+inline
+string const tostr(LyXTabular::BoxType const & num)
{
switch(num) {
case LyXTabular::BOX_NONE:
}
-string const type2string(bool flag)
-{
- return (flag ? "true" : "false");
-}
-
-
void LyXTabular::Write(Buffer const * buf, ostream & os) const
{
// header line
- os << "<LyXTabular"
- << write_attribute("version", 1)
+ os << "<lyxtabular"
+ << write_attribute("version", 2)
<< write_attribute("rows", rows_)
<< write_attribute("columns", columns_)
<< ">\n";
// global longtable options
- os << "<Features"
- << write_attribute("rotate", type2string(rotate))
- << write_attribute("islongtable", type2string(is_long_tabular))
+ 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", type2string(column_info[j].alignment))
- << write_attribute("valignment", type2string(column_info[j].valignment))
- << write_attribute("leftline", type2string(column_info[j].left_line))
- << write_attribute("rightline", type2string(column_info[j].right_line))
+ 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())
<< ">\n";
}
for (int i = 0; i < rows_; ++i) {
- os << "<Row"
- << write_attribute("topline", type2string(row_info[i].top_line))
- << write_attribute("bottomline", type2string(row_info[i].bottom_line))
- << write_attribute("newpage", type2string(row_info[i].newpage))
+ 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) {
#if 0
if (!i) {
- os << "<Column"
- << write_attribute("alignment", type2string(column_info[j].alignment))
- << write_attribute("valignment", type2string(column_info[j].valignment))
- << write_attribute("leftline", type2string(column_info[j].left_line))
- << write_attribute("rightline", type2string(column_info[j].right_line))
+ 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";
} else {
- os << "<Column>\n";
+ os << "<column>\n";
}
#endif
- os << "<Cell"
+ os << "<cell"
<< write_attribute("multicolumn", cell_info[i][j].multicolumn)
- << write_attribute("alignment", type2string(cell_info[i][j].alignment))
- << write_attribute("valignment", type2string(cell_info[i][j].valignment))
- << write_attribute("topline", type2string(cell_info[i][j].top_line))
- << write_attribute("bottomline", type2string(cell_info[i][j].bottom_line))
- << write_attribute("leftline", type2string(cell_info[i][j].left_line))
- << write_attribute("rightline", type2string(cell_info[i][j].right_line))
- << write_attribute("rotate", type2string(cell_info[i][j].rotate))
- << write_attribute("usebox", type2string(cell_info[i][j].usebox))
+ << 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";
+ << "</cell>\n";
#if 0
- << "</Column>\n";
+ << "</column>\n";
#endif
}
- os << "</Row>\n";
+ os << "</row>\n";
}
- os << "</LyXTabular>\n";
+ os << "</lyxtabular>\n";
}
+// I would have liked a fromstr template a lot better. (Lgb)
+
+static inline
bool string2type(string const str, LyXAlignment & num)
{
if (str == "none")
}
+static inline
bool string2type(string const str, LyXTabular::VAlignment & num)
{
if (str == "top")
}
+static inline
bool string2type(string const str, LyXTabular::BoxType & num)
{
if (str == "none")
}
+static inline
bool string2type(string const str, bool & num)
{
if (str == "true")
return true;
}
+
static
bool getTokenValue(string const & str, const char * token, string & ret)
{
}
-//#define USE_OLD_READFORMAT
-
-#ifndef USE_OLD_READFORMAT
static
bool getTokenValue(string const & str, const char * token, int & num)
{
return string2type(tmp, flag);
}
-#else
-
-static
-bool getTokenValue(string const & str, const char * token, int & num)
-{
- string::size_type pos = str.find(token);
- char ch = str[pos + strlen(token)];
-
- if ((pos == string::npos) || (ch != '='))
- return false;
- string ret;
- pos += strlen(token) + 1;
- ch = str[pos];
- if ((ch != '"') && (ch != '\'')) { // only read till next space
- if (!isdigit(ch))
- return false;
- ret += ch;
- }
- ++pos;
- while((pos < str.length() - 1) && isdigit(str[pos]))
- ret += str[pos++];
-
- num = strToInt(ret);
- return true;
-}
-
-
-static
-bool getTokenValue(string const & str, const char * token, LyXAlignment & num)
-{
- int tmp;
- bool const ret = getTokenValue(str, token, tmp);
- num = static_cast<LyXAlignment>(tmp);
- return ret;
-}
-
-
-static
-bool getTokenValue(string const & str, const char * token,
- LyXTabular::VAlignment & num)
-{
- int tmp;
- bool const ret = getTokenValue(str, token, tmp);
- num = static_cast<LyXTabular::VAlignment>(tmp);
- return ret;
-}
-
-
-static
-bool getTokenValue(string const & str, const char * token,
- LyXTabular::BoxType & num)
-{
- int tmp;
- bool ret = getTokenValue(str, token, tmp);
- num = static_cast<LyXTabular::BoxType>(tmp);
- return ret;
-}
-
-
-static
-bool getTokenValue(string const & str, const char * token, bool & flag)
-{
- string::size_type pos = str.find(token);
- char ch = str[pos + strlen(token)];
-
- if ((pos == string::npos) || (ch != '='))
- return false;
- string ret;
- pos += strlen(token) + 1;
- ch = str[pos];
- if ((ch != '"') && (ch != '\'')) { // only read till next space
- if (!isdigit(ch))
- return false;
- ret += ch;
- }
- ++pos;
- while((pos < str.length() - 1) && isdigit(str[pos]))
- ret += str[pos++];
-
- flag = strToInt(ret);
- return true;
-}
-
-#endif
static inline
void l_getline(istream & is, string & str)
}
-#ifndef USE_OLD_READFORMAT
-
void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
{
- string line;
- istream & is = lex.getStream();
+ string line;
+ istream & is = lex.getStream();
- l_getline(is, line);
- if (!prefixIs(line, "<LyXTabular ")) {
- OldFormatRead(lex, line);
- return;
- }
+ l_getline(is, line);
+ if (!prefixIs(line, "<lyxtabular ")
+ && !prefixIs(line, "<LyXTabular ")) {
+ OldFormatRead(lex, line);
+ return;
+ }
- int version;
+ int version;
+ if (!getTokenValue(line, "version", version))
+ return;
+ if (version == 1)
+ ReadOld(buf, is, lex, line);
+ else if (version == 2)
+ ReadNew(buf, is, lex, line);
+}
+
+
+void LyXTabular::ReadNew(Buffer const * buf, istream & is,
+ LyXLex & lex, string const & l)
+{
+ string line(l);
int rows_arg;
- int columns_arg;
- if (!getTokenValue(line, "version", version))
- return;
if (!getTokenValue(line, "rows", rows_arg))
return;
+ int columns_arg;
if (!getTokenValue(line, "columns", columns_arg))
return;
Init(rows_arg, columns_arg);
l_getline(is, line);
- if (!prefixIs(line, "<Features")) {
- lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
+ if (!prefixIs(line, "<features")) {
+ lyxerr << "Wrong tabular format (expected <features ...> got" <<
line << ")" << endl;
return;
}
for (int j = 0; j < columns_; ++j) {
l_getline(is,line);
- if (!prefixIs(line,"<Column")) {
- lyxerr << "Wrong tabular format (expected <Column ...> got" <<
+ if (!prefixIs(line,"<column")) {
+ lyxerr << "Wrong tabular format (expected <column ...> got" <<
line << ")" << endl;
return;
}
for (int i = 0; i < rows_; ++i) {
l_getline(is, line);
- if (!prefixIs(line, "<Row")) {
- lyxerr << "Wrong tabular format (expected <Row ...> got" <<
+ if (!prefixIs(line, "<row")) {
+ lyxerr << "Wrong tabular format (expected <row ...> got" <<
line << ")" << endl;
return;
}
getTokenValue(line, "newpage", row_info[i].newpage);
for (int j = 0; j < columns_; ++j) {
l_getline(is, line);
- if (!prefixIs(line, "<Cell")) {
- lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
+ if (!prefixIs(line, "<cell")) {
+ lyxerr << "Wrong tabular format (expected <cell ...> got" <<
line << ")" << endl;
return;
}
cell_info[i][j].inset.Read(buf, lex);
l_getline(is, line);
}
- if (line != "</Cell>") {
- lyxerr << "Wrong tabular format (expected </Cell> got" <<
+ if (line != "</cell>") {
+ lyxerr << "Wrong tabular format (expected </cell> got" <<
line << ")" << endl;
return;
}
}
l_getline(is, line);
- if (line != "</Row>") {
- lyxerr << "Wrong tabular format (expected </Row> got" <<
+ if (line != "</row>") {
+ lyxerr << "Wrong tabular format (expected </row> got" <<
line << ")" << endl;
return;
}
}
- while (line != "</LyXTabular>") {
+ while (line != "</lyxtabular>") {
l_getline(is, line);
}
set_row_column_number_info();
}
-#else
-
-void LyXTabular::Read(Buffer const * buf, LyXLex & lex)
-{
- string line;
- istream & is = lex.getStream();
-
- l_getline(is, line);
- if (!prefixIs(line, "<LyXTabular ")) {
- OldFormatRead(lex, line);
- return;
- }
-
- int version;
- int rows_arg;
- int columns_arg;
- if (!getTokenValue(line, "version", version))
- return;
- if (!getTokenValue(line, "rows", rows_arg))
- return;
- if (!getTokenValue(line, "columns", columns_arg))
- return;
- Init(rows_arg, columns_arg);
- l_getline(is, line);
- if (!prefixIs(line, "<Features ")) {
- lyxerr << "Wrong tabular format (expected <Feture ...> got" <<
- line << ")" << endl;
- return;
- }
- getTokenValue(line, "islongtable", is_long_tabular);
- getTokenValue(line, "endhead", endhead);
- getTokenValue(line, "endfirsthead", endfirsthead);
- getTokenValue(line, "endfoot", endfoot);
- getTokenValue(line, "endlastfoot", endlastfoot);
-
- for (int i = 0; i < rows_; ++i) {
- l_getline(is, line);
- if (!prefixIs(line, "<Row ")) {
- lyxerr << "Wrong tabular format (expected <Row ...> got" <<
- line << ")" << endl;
- return;
- }
- getTokenValue(line, "topline", row_info[i].top_line);
- getTokenValue(line, "bottomline", row_info[i].bottom_line);
- getTokenValue(line, "newpage", row_info[i].newpage);
- for (int j = 0; j < columns_; ++j) {
- l_getline(is,line);
- if (!prefixIs(line,"<Column")) {
- lyxerr << "Wrong tabular format (expected <Column ...> got" <<
- line << ")" << endl;
- return;
- }
- if (!i) {
- getTokenValue(line, "alignment", column_info[j].alignment);
- getTokenValue(line, "valignment", column_info[j].valignment);
- getTokenValue(line, "leftline", column_info[j].left_line);
- getTokenValue(line, "rightline", column_info[j].right_line);
- getTokenValue(line, "width", column_info[j].p_width);
- getTokenValue(line, "special", column_info[j].align_special);
- }
- l_getline(is, line);
- if (!prefixIs(line, "<Cell")) {
- lyxerr << "Wrong tabular format (expected <Cell ...> got" <<
- line << ")" << endl;
- return;
- }
- getTokenValue(line, "multicolumn", cell_info[i][j].multicolumn);
- getTokenValue(line, "alignment", cell_info[i][j].alignment);
- getTokenValue(line, "valignment", cell_info[i][j].valignment);
- getTokenValue(line, "topline", cell_info[i][j].top_line);
- getTokenValue(line, "bottomline", cell_info[i][j].bottom_line);
- getTokenValue(line, "leftline", cell_info[i][j].left_line);
- getTokenValue(line, "rightline", cell_info[i][j].right_line);
- getTokenValue(line, "rotate", cell_info[i][j].rotate);
- getTokenValue(line, "usebox", cell_info[i][j].usebox);
- getTokenValue(line, "width", cell_info[i][j].p_width);
- getTokenValue(line, "special", cell_info[i][j].align_special);
- l_getline(is, line);
- if (prefixIs(line, "\\begin_inset")) {
- cell_info[i][j].inset.Read(buf, lex);
- l_getline(is, line);
- }
- if (line != "</Cell>") {
- lyxerr << "Wrong tabular format (expected </Cell> got" <<
- line << ")" << endl;
- return;
- }
- l_getline(is, line);
- if (line != "</Column>") {
- lyxerr << "Wrong tabular format (expected </Column> got" <<
- line << ")" << endl;
- return;
- }
- }
- l_getline(is, line);
- if (line != "</Row>") {
- lyxerr << "Wrong tabular format (expected </Row> got" <<
- line << ")" << endl;
- return;
- }
- }
- while (line != "</LyXTabular>") {
- l_getline(is, line);
- }
- set_row_column_number_info();
-}
-#endif
void LyXTabular::OldFormatRead(LyXLex & lex, string const & fl)
{
int version;
- int i, j;
+ int i;
+ int j;
int rows_arg = 0;
int columns_arg = 0;
int is_long_tabular_arg = false;
//+ the single row and columns (cells) +
//+---------------------------------------------------------------------
- //int bret;
for (int i = 0; i < rows_; ++i) {
ret += TeXTopHLine(os, i);
int bret = ret;
else
os << " ";
- return ret * 0; // eh? (Lgb)
+ return ret;
}