the convert patch

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@9538 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2005-01-27 21:05:44 +00:00
parent 76355ad107
commit 342cdf4322
76 changed files with 538 additions and 320 deletions

View File

@ -1,3 +1,7 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* configure.ac: add src/support/tests/Makefile
2005-01-21 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* configure.ac: indicate in final info whether aiksaurus is used.

View File

@ -413,6 +413,7 @@ AC_CONFIG_FILES([Makefile m4/Makefile \
src/graphics/Makefile \
src/insets/Makefile \
src/support/Makefile \
src/support/tests/Makefile \
src/frontends/Makefile \
src/frontends/controllers/Makefile \
src/frontends/xforms/Makefile \

View File

@ -206,6 +206,7 @@ src/paragraph.C
src/rowpainter.C
src/support/filefilterlist.C
src/support/package.C.in
src/support/path_defines.C
src/text.C
src/text2.C
src/text3.C

View File

@ -88,7 +88,6 @@ using lyx::support::IsDirWriteable;
using lyx::support::MakeDisplayPath;
using lyx::support::MakeAbsPath;
using lyx::support::package;
using lyx::support::strToUnsignedInt;
using std::endl;
using std::istringstream;
@ -966,7 +965,7 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
break;
case LFUN_BOOKMARK_GOTO:
flag.enabled(bv_->isSavedPosition(strToUnsignedInt(cmd.argument)));
flag.enabled(bv_->isSavedPosition(convert<unsigned int>(cmd.argument)));
break;
case LFUN_TRACK_CHANGES:
flag.enabled(true);
@ -975,7 +974,7 @@ FuncStatus BufferView::Pimpl::getStatus(FuncRequest const & cmd)
case LFUN_OUTPUT_CHANGES: {
LaTeXFeatures features(*buf, buf->params(), false);
flag.enabled(buf && buf->params().tracking_changes
flag.enabled(buf && buf->params().tracking_changes
&& features.isAvailable("dvipost"));
flag.setOnOff(buf->params().output_changes);
break;
@ -1052,11 +1051,11 @@ bool BufferView::Pimpl::dispatch(FuncRequest const & cmd)
break;
case LFUN_BOOKMARK_SAVE:
savePosition(strToUnsignedInt(cmd.argument));
savePosition(convert<unsigned int>(cmd.argument));
break;
case LFUN_BOOKMARK_GOTO:
restorePosition(strToUnsignedInt(cmd.argument));
restorePosition(convert<unsigned int>(cmd.argument));
break;
case LFUN_REF_GOTO: {

View File

@ -1,20 +1,28 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* lyxlayout.[Ch]: change some vars from float to double
* buffer.C (readFile): make a local var const
* Several files: use convert<> instead of atoi,strToXXX and friends
2005-01-24 Jürgen Spitzmüller <j.spitzmueller@gmx.de>
* LaTeXFeatures.[Ch]: Add a static list packages_ that
holds the contens of packages.lst. New functions getAvailable
and isAvailable to parse and check that list, resp.
* LyXAction.C:
* lfuns.h:
* BufferView_pimpl.C: new LFUN_OUTPUT_CHANGES.
* bufferparams.[Ch]: new param output_changes.
* Buffer.C: increase file format to 240.
Use output_changes and isVailable.
* changes.[Ch]:
* paragraph.C:
* changes.[Ch]:
* paragraph.C:
* paragraph_pimpl.C: Use output_changes and isVailable.
2005-01-23 Angus Leeming <leeming@lyx.org>
@ -28,7 +36,7 @@
2005-01-20 Angus Leeming <leeming@lyx.org>
* lyxfont.C (setLyXFamily, setLyXSeries, setLyXShape, setLyXSize)
* lyxfont.C (setLyXFamily, setLyXSeries, setLyXShape, setLyXSize)
(setLyXMisc): (char string literal) != (char string literal) is
performing a comparison on the addresses. Convert one operand
explicitly to string to guarantee expected behaviour.
@ -40,7 +48,7 @@
* lyxlex_pimpl.[Ch]: use USE_COMPRESSION guard.
* output_plaintext.C: remove unneeded #include gzstream.h.
2005-01-20 Angus Leeming <leeming@lyx.org>
* SpellBase.h: rename some of the elements of the Result enum.

View File

@ -15,16 +15,15 @@
#include "LaTeX.h" // TeXErrors
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include "support/systemcall.h"
#include <boost/format.hpp>
#include <fstream>
using lyx::support::atoi;
using lyx::support::ChangeExtension;
using lyx::support::OnlyFilename;
using lyx::support::split;
@ -82,7 +81,7 @@ int Chktex::scanLogFile(TeXErrors & terr)
token = split(token, warno, ':');
token = split(token, warning, ':');
int const lineno = atoi(line);
int const lineno = convert<int>(line);
#if USE_BOOST_FORMAT
msg % warno;

View File

@ -18,9 +18,7 @@
#include <sstream>
#include <string>
using lyx::support::strToDbl;
//using std::ios;
using std::ostream;
using std::ostringstream;
using std::string;
@ -45,11 +43,11 @@ string const Spacing::getValueAsString() const
double Spacing::getValue() const
{
return strToDbl(getValueAsString());
return convert<double>(getValueAsString());
}
void Spacing::set(Spacing::Space sp, float val)
void Spacing::set(Spacing::Space sp, double val)
{
set(sp, convert<string>(val));
}
@ -59,7 +57,7 @@ void Spacing::set(Spacing::Space sp, string const & val)
{
space = sp;
if (sp == Other) {
switch (int(strToDbl(val) * 1000 + 0.5)) {
switch (int(convert<double>(val) * 1000 + 0.5)) {
case 1000:
space = Single;
break;

View File

@ -35,7 +35,7 @@ public:
///
Spacing() : space(Default), value("1.0") {}
///
Spacing(Spacing::Space sp, float val = 1.0) {
Spacing(Spacing::Space sp, double val = 1.0) {
set(sp, val);
}
Spacing(Spacing::Space sp, std::string const & val) {
@ -52,7 +52,7 @@ public:
///
Spacing::Space getSpace() const { return space; }
///
void set(Spacing::Space sp, float val = 1.0);
void set(Spacing::Space sp, double val = 1.0);
///
void set(Spacing::Space sp, std::string const & val);
///

View File

@ -111,7 +111,6 @@ using lyx::support::removeAutosaveFile;
using lyx::support::rename;
using lyx::support::RunCommand;
using lyx::support::split;
using lyx::support::strToInt;
using lyx::support::subst;
using lyx::support::tempName;
using lyx::support::trim;
@ -609,7 +608,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
//lyxerr << " dot found at " << dot << endl;
if (dot != string::npos)
tmp_format.erase(dot, 1);
int file_format = strToInt(tmp_format);
int const file_format = convert<int>(tmp_format);
//lyxerr << "format: " << file_format << endl;
if (file_format != LYX_FORMAT) {
@ -650,7 +649,7 @@ bool Buffer::readFile(LyXLex & lex, string const & filename, pit_type const pit)
filename));
return false;
} else {
bool ret = readFile(tmpfile, pit);
bool const ret = readFile(tmpfile, pit);
// Do stuff with tmpfile name and buffer name here.
return ret;
}
@ -1185,7 +1184,7 @@ void Buffer::validate(LaTeXFeatures & features) const
{
LyXTextClass const & tclass = params().getLyXTextClass();
if (features.isAvailable("dvipost") && params().tracking_changes
if (features.isAvailable("dvipost") && params().tracking_changes
&& params().output_changes) {
features.require("dvipost");
features.require("color");

View File

@ -15,14 +15,13 @@
#include "debug.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lyxlib.h"
#include <boost/regex.hpp>
#include <fstream>
using lyx::support::atoi;
using lyx::support::LibFileSearch;
using boost::regex;
@ -66,7 +65,7 @@ bool CharacterSet::loadFile(string const & fname)
while (getline(ifs, line)) {
smatch sub;
if (regex_match(line, sub, reg)) {
int const n = atoi(sub.str(1));
int const n = convert<int>(sub.str(1));
string const str = sub.str(2);
if (lyxerr.debugging(Debug::KBMAP))
lyxerr << "Chardef: " << n

View File

@ -1,3 +1,7 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* debug.C: use convert<> instead of atoi,strToXXX and friends
2005-01-20 Asger Ottar Alstrup <aalstrup@laerdal.dk>
* pch.h: use the HAVE_UNISTD_H preprocessor guard.

View File

@ -14,6 +14,7 @@
#include "debug.h"
#include "gettext.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include <iostream>
@ -22,7 +23,6 @@
using lyx::support::ascii_lowercase;
using lyx::support::bformat;
using lyx::support::isStrInt;
using lyx::support::strToInt;
using std::setw;
using std::string;
@ -61,7 +61,7 @@ lyx_debug_trait::type lyx_debug_trait::value(string const & val)
break;
// Is it a number?
if (isStrInt(tmp))
l |= static_cast<type>(strToInt(tmp));
l |= static_cast<type>(convert<int>(tmp));
else
// Search for an explicit name
for (int i = 0 ; i < numErrorTags ; ++i)

View File

@ -14,6 +14,7 @@
#include "debug.h"
#include "gettext.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include <iostream>
@ -22,7 +23,6 @@
using lyx::support::ascii_lowercase;
using lyx::support::bformat;
using lyx::support::isStrInt;
using lyx::support::strToInt;
using std::setw;
using std::string;
@ -78,13 +78,13 @@ lyx_debug_trait::type lyx_debug_trait::value(string const & val)
type l = Debug::NONE;
string v(val);
while (!v.empty()) {
string::size_type st = v.find(',');
string tmp(ascii_lowercase(v.substr(0, st)));
string::size_type const st = v.find(',');
string const tmp(ascii_lowercase(v.substr(0, st)));
if (tmp.empty())
break;
// Is it a number?
if (isStrInt(tmp))
l |= static_cast<type>(strToInt(tmp));
l |= static_cast<type>(convert<int>(tmp));
else
// Search for an explicit name
for (int i = 0 ; i < numErrorTags ; ++i)

View File

@ -1,3 +1,7 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* Several files: use convert<> instead of atoi,strToXXX and friends
2005-01-10 Angus Leeming <leeming@lyx.org>
* ghelpers.C:

View File

@ -26,9 +26,9 @@
#include "paper.h"
#include "lyxrc.h" // for lyxrc.default_papersize
#include "support/convert.h"
#include "support/lyxlib.h" // for float_equal
#include "support/lstrings.h"
#include "support/convert.h"
#include "debug.h"
@ -38,7 +38,6 @@ using std::string;
namespace lyx {
using support::float_equal;
using support::strToDbl;
using support::token;
namespace frontend {
@ -372,7 +371,7 @@ void GGraphics::update() {
displaycombo_->set_active(0);
}
outputscalespin_->get_adjustment()->set_value(strToDbl(igp.scale));
outputscalespin_->get_adjustment()->set_value(convert<double>(igp.scale));
widthspin_->get_adjustment()->set_value(igp.width.value());
unitsComboFromLength(widthunitscombo_, stringcol_,
igp.width, defaultUnit);
@ -381,7 +380,7 @@ void GGraphics::update() {
igp.height, defaultUnit);
if (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
&& !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
// scaling sizing mode
setscalingradio_->set_active(true);
} else {
@ -400,7 +399,7 @@ void GGraphics::update() {
clipcheck_->set_active(igp.clip);
// the extra section
anglespin_->get_adjustment()->set_value(strToDbl(igp.rotateAngle));
anglespin_->get_adjustment()->set_value(convert<double>(igp.rotateAngle));
int origin_pos;
if (igp.rotateOrigin.empty()) {

View File

@ -21,8 +21,8 @@
#include "PrinterParams.h"
#include "support/lstrings.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include <libglademm.h>
@ -47,9 +47,9 @@ void GPrint::apply()
pp.all_pages = all_->get_active();
pp.from_page = pp.to_page = 0;
if (!fromEntry_->get_text().empty()) {
pp.from_page = strToInt(fromEntry_->get_text());
pp.from_page = convert<int>(fromEntry_->get_text());
if (!toEntry_->get_text().empty())
pp.to_page = strToInt(toEntry_->get_text());
pp.to_page = convert<int>(toEntry_->get_text());
}
pp.odd_pages = odd_->get_active();
pp.even_pages = even_->get_active();
@ -93,7 +93,7 @@ void GPrint::updateUI()
if (fromTo_->get_active()) {
string from = fromEntry_->get_text();
string to = toEntry_->get_text();
if (from.empty() || (!to.empty() && strToInt(from) > strToInt(to)))
if (from.empty() || (!to.empty() && convert<int>(from) > convert<int>(to)))
activate = ButtonPolicy::SMI_INVALID;
}
bool const enableCounter = printer_->get_active();

View File

@ -26,6 +26,7 @@
#include "frontends/LyXView.h"
#include "frontends/lyx_gui.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#include "support/filetools.h"
@ -33,8 +34,6 @@
#include <cmath> // fabs()
#include <vector>
using lyx::support::strToDbl;
using std::endl;
using std::string;
@ -131,7 +130,7 @@ XftPattern * xftFontLoader::getFontPattern(LyXFont::FONT_FAMILY family,
string ffamily;
int fweight;
int fslant;
double fsize = strToDbl(lyxrc.font_sizes[size]) * lyxrc.zoom / 100.0;
double fsize = convert<double>(lyxrc.font_sizes[size]) * lyxrc.zoom / 100.0;
XftPattern *fpat = XftPatternCreate();
ffamily = familyString(family);

View File

@ -1,7 +1,11 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* Several files: use convert<> instead of atoi,strToXXX and friends
2005-01-20 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* floatplacement.C (heredefinitelyClicked): remove bogus
semicolon.
semicolon.
2005-01-15 Angus Leeming <leeming@lyx.org>

View File

@ -42,8 +42,6 @@
namespace external = lyx::external;
using lyx::support::isStrDbl;
using lyx::support::strToDbl;
using lyx::support::strToInt;
using lyx::support::token;
using lyx::support::trim;
@ -134,7 +132,7 @@ void getDisplay(external::DisplayType & display,
if (!displayCB.isChecked())
display = external::NoDisplay;
scale = strToInt(fromqstr(scaleED.text()));
scale = convert<int>(fromqstr(scaleED.text()));
}
@ -211,7 +209,7 @@ void getSize(external::ResizeData & data,
if (isValidLength(width, &w))
data.width = w;
else if (isStrDbl(width))
data.width = LyXLength(strToDbl(width),
data.width = LyXLength(convert<double>(width),
static_cast<LyXLength::UNIT>(unit));
else
data.width = LyXLength();
@ -255,10 +253,10 @@ void getCrop(external::ClipData & data,
if (!bb_changed)
return;
data.bbox.xl = strToInt(fromqstr(xlED.text()));
data.bbox.yb = strToInt(fromqstr(ybED.text()));
data.bbox.xr = strToInt(fromqstr(xrED.text()));
data.bbox.yt = strToInt(fromqstr(ytED.text()));
data.bbox.xl = convert<int>(fromqstr(xlED.text()));
data.bbox.yb = convert<int>(fromqstr(ybED.text()));
data.bbox.xr = convert<int>(fromqstr(xrED.text()));
data.bbox.yt = convert<int>(fromqstr(ytED.text()));
}

View File

@ -18,6 +18,7 @@
#include "controllers/ButtonController.h"
#include "controllers/ControlExternal.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -38,7 +39,6 @@
using lyx::support::float_equal;
using lyx::support::isStrDbl;
using lyx::support::strToDbl;
using std::string;
namespace lyx {
@ -100,7 +100,7 @@ bool QExternalDialog::activateAspectratio() const
if (wstr.empty())
return false;
bool const wIsDbl = isStrDbl(wstr);
if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
return false;
LyXLength l;
if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
@ -110,7 +110,7 @@ bool QExternalDialog::activateAspectratio() const
if (hstr.empty())
return false;
bool const hIsDbl = isStrDbl(hstr);
if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
return false;
if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
return false;

View File

@ -28,8 +28,8 @@
#include "insets/insetgraphicsParams.h"
#include "support/lstrings.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
#include <qlineedit.h>
@ -41,8 +41,6 @@
#include <cmath>
using lyx::support::float_equal;
using lyx::support::strToDbl;
using lyx::support::strToInt;
using lyx::support::token;
#ifndef CXX_GLOBAL_CSTD
@ -257,7 +255,7 @@ void QGraphics::update_contents()
dialog_->widthUnit->insertItem(unit_name_gui[i], -1);
if (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
&& !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
dialog_->width->setText(toqstr(igp.scale));
dialog_->widthUnit->setCurrentItem(0);
} else {
@ -320,8 +318,8 @@ void QGraphics::apply()
string rtX(fromqstr(dialog_->rtX->text()));
string rtY(fromqstr(dialog_->rtY->text()));
int bb_sum =
strToInt(lbX) + strToInt(lbY) +
strToInt(rtX) + strToInt(rtX);
convert<int>(lbX) + convert<int>(lbY) +
convert<int>(rtX) + convert<int>(rtX);
if (bb_sum) {
if (lbX.empty())
bb = "0 ";
@ -378,11 +376,11 @@ void QGraphics::apply()
igp.noUnzip = dialog_->unzipCB->isChecked();
igp.lyxscale = strToInt(fromqstr(dialog_->displayscale->text()));
igp.lyxscale = convert<int>(fromqstr(dialog_->displayscale->text()));
igp.rotateAngle = fromqstr(dialog_->angle->text());
float rotAngle = strToDbl(igp.rotateAngle);
double rotAngle = convert<double>(igp.rotateAngle);
if (std::abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
igp.rotateAngle = convert<string>(rotAngle);

View File

@ -24,7 +24,7 @@
#include "ui/QPrefScreenFontsModule.h"
#include "ui/QPrefColorsModule.h"
#if defined(__CYGWIN__) || defined(__CYGWIN32__)
#include "ui/QPrefCygwinPathModule.h"
#include "ui/QPrefCygwinPathModule.h"
#endif
#include "ui/QPrefDisplayModule.h"
#include "ui/QPrefPathsModule.h"
@ -61,7 +61,6 @@
#include <sstream>
using lyx::support::compare_no_case;
using lyx::support::strToDbl;
using std::distance;
using std::endl;

View File

@ -27,7 +27,6 @@
#include <qlineedit.h>
#include <qpushbutton.h>
using lyx::support::strToDbl;
using std::string;
@ -59,7 +58,7 @@ void QWrap::build_dialog()
void QWrap::apply()
{
double const value = strToDbl(fromqstr(dialog_->widthED->text()));
double const value = convert<double>(fromqstr(dialog_->widthED->text()));
LyXLength::UNIT unit = dialog_->unitsLC->currentLengthItem();
if (dialog_->widthED->text().isEmpty())
unit = LyXLength::UNIT_NONE;

View File

@ -19,6 +19,7 @@
#include "frontends/lyx_gui.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
@ -38,7 +39,6 @@ using lyx::support::LibFileSearch;
using lyx::support::OnlyPath;
using lyx::support::QuoteName;
using lyx::support::Systemcall;
using lyx::support::strToDbl;
using std::endl;
using std::make_pair;
@ -316,7 +316,7 @@ qfont_loader::font_info::font_info(LyXFont const & f)
}
}
font.setPointSizeFloat(strToDbl(lyxrc.font_sizes[f.size()])
font.setPointSizeFloat(convert<double>(lyxrc.font_sizes[f.size()])
* lyxrc.zoom / 100.0);
switch (f.series()) {

View File

@ -1,3 +1,7 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* Several files: use convert<> instead of atoi,strToXXX and friends
2005-01-20 Angus Leeming <leeming@lyx.org>
* FormPreferences.C: change the tooltip messages to reflect the

View File

@ -32,7 +32,6 @@ using std::string;
namespace lyx {
using support::atoi;
using support::token;
namespace frontend {
@ -143,14 +142,14 @@ void FontInfo::query()
string name(list[i]);
lyxerr[Debug::FONT] << "match #" << i << ' '
<< name << endl;
sizes[i] = atoi(token(name, '-', 7));
sizes[i] = convert<int>(token(name, '-', 7));
strings[i] = name;
if (sizes[i] == 0) {
if (scaleindex == -1) {
scaleindex = i;
}
scalable = true;
} else if (atoi(token(name, '-', 12)) == 0)
} else if (convert<int>(token(name, '-', 12)) == 0)
// Ignore bogus matches of scalable fonts.
sizes[i] = 0;
};

View File

@ -47,8 +47,6 @@ using support::bformat;
using support::float_equal;
using support::getStringFromVector;
using support::isStrDbl;
using support::strToDbl;
using support::strToInt;
using support::token;
using support::trim;
@ -145,7 +143,7 @@ void getDisplay(external::DisplayType & display,
if (!fl_get_button(displayCB))
display = external::NoDisplay;
scale = strToInt(getString(scaleED));
scale = convert<int>(getString(scaleED));
}
@ -243,13 +241,12 @@ void getSize(external::ResizeData & data,
if (isValidLength(width, &w))
data.width = w;
else if (isStrDbl(width))
data.width = LyXLength(strToDbl(width),
data.width = LyXLength(convert<double>(width),
static_cast<LyXLength::UNIT>(unit));
else
data.width = LyXLength();
data.scale = string();
data.scale.erase();
} else {
// scaling instead of a width
data.scale = width;
@ -299,10 +296,10 @@ void getCrop(external::ClipData & data,
if (!bb_changed)
return;
data.bbox.xl = strToInt(getString(xlED));
data.bbox.yb = strToInt(getString(ybED));
data.bbox.xr = strToInt(getString(xrED));
data.bbox.yt = strToInt(getString(ytED));
data.bbox.xl = convert<int>(getString(xlED));
data.bbox.yb = convert<int>(getString(ybED));
data.bbox.xr = convert<int>(getString(xrED));
data.bbox.yt = convert<int>(getString(ytED));
}
@ -696,7 +693,7 @@ bool FormExternal::activateAspectratio() const
if (wstr.empty())
return false;
bool const wIsDbl = isStrDbl(wstr);
if (wIsDbl && float_equal(strToDbl(wstr), 0.0, 0.05))
if (wIsDbl && float_equal(convert<double>(wstr), 0.0, 0.05))
return false;
LyXLength l;
if (!wIsDbl && (!isValidLength(wstr, &l) || l.zero()))
@ -706,7 +703,7 @@ bool FormExternal::activateAspectratio() const
if (hstr.empty())
return false;
bool const hIsDbl = isStrDbl(hstr);
if (hIsDbl && float_equal(strToDbl(hstr), 0.0, 0.05))
if (hIsDbl && float_equal(convert<double>(hstr), 0.0, 0.05))
return false;
if (!hIsDbl && (!isValidLength(hstr, &l) || l.zero()))
return false;

View File

@ -51,8 +51,6 @@ namespace lyx {
using support::bformat;
using support::float_equal;
using support::getStringFromVector;
using support::strToDbl;
using support::strToInt;
using support::token;
namespace frontend {
@ -306,7 +304,7 @@ void FormGraphics::apply()
igp.filename.set(getString(file_->input_filename),
kernel().bufferFilepath());
igp.lyxscale = strToInt(getString(file_->input_lyxscale));
igp.lyxscale = convert<int>(getString(file_->input_lyxscale));
if (igp.lyxscale == 0) {
igp.lyxscale = 100;
}
@ -332,13 +330,13 @@ void FormGraphics::apply()
if (fl_get_choice(file_->choice_width) == 1) {
igp.scale = getString(file_->input_width);
if (igp.scale.empty()
|| float_equal(strToDbl(igp.scale), 0.0, 0.05)
|| float_equal(strToDbl(igp.scale), 100.0, 0.05)) {
igp.scale = string();
|| float_equal(convert<double>(igp.scale), 0.0, 0.05)
|| float_equal(convert<double>(igp.scale), 100.0, 0.05)) {
igp.scale.erase();
}
igp.width = LyXLength();
} else {
igp.scale = string();
igp.scale.erase();
igp.width = LyXLength(getLengthFromWidgets(file_->input_width,
file_->choice_width));
}
@ -411,7 +409,7 @@ void FormGraphics::apply()
igp.rotateAngle = getString(extra_->input_rotate_angle);
// map angle into -360 (clock-wise) to +360 (counter clock-wise)
float rotAngle = strToDbl(igp.rotateAngle);
double rotAngle = convert<double>(igp.rotateAngle);
if (std::abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
igp.rotateAngle = convert<string>(rotAngle);
@ -461,7 +459,7 @@ void FormGraphics::update() {
}
// set width input fields according to scaling or width/height input
if (!igp.scale.empty() && !float_equal(strToDbl(igp.scale), 0.0, 0.05)) {
if (!igp.scale.empty() && !float_equal(convert<double>(igp.scale), 0.0, 0.05)) {
fl_set_input_filter(file_->input_width, fl_unsigned_float_filter);
fl_set_input_maxchars(file_->input_width, 0);
fl_set_input(file_->input_width, igp.scale.c_str());
@ -478,7 +476,7 @@ void FormGraphics::update() {
// disable height input in case of scaling
bool const disable_height = (!igp.scale.empty()
&& !float_equal(strToDbl(igp.scale), 0.0, 0.05));
&& !float_equal(convert<double>(igp.scale), 0.0, 0.05));
setEnabled(file_->input_height, !disable_height);
setEnabled(file_->choice_height, !disable_height);
@ -502,11 +500,9 @@ void FormGraphics::update() {
// the extra section
fl_set_input(extra_->input_rotate_angle, igp.rotateAngle.c_str());
int origin_pos;
if (igp.rotateOrigin.empty()) {
origin_pos = 1;
} else {
origin_pos = 1 + findPos(origins_, igp.rotateOrigin);
int origin_pos = 1;
if (!igp.rotateOrigin.empty()) {
origin_pos += findPos(origins_, igp.rotateOrigin);
}
fl_set_choice(extra_->choice_origin, origin_pos);

View File

@ -28,6 +28,7 @@
#include "LColor.h"
#include "lyxfont.h"
#include "support/convert.h"
#include "support/lstrings.h"
#include "support/package.h"
#include "support/filetools.h"
@ -52,7 +53,6 @@ using support::AddName;
using support::ChangeExtension;
using support::package;
using support::rtrim;
using support::strToDbl;
using support::trim;
namespace frontend {
@ -2825,38 +2825,37 @@ bool FormPreferences::ScreenFonts::input()
// Make sure that all fonts all have positive entries
// Also note that an empty entry is returned as 0.0 by strToDbl
if (0.0 >= strToDbl(getString(dialog_->input_tiny))
|| 0.0 >= strToDbl(getString(dialog_->input_script))
|| 0.0 >= strToDbl(getString(dialog_->input_footnote))
|| 0.0 >= strToDbl(getString(dialog_->input_small))
|| 0.0 >= strToDbl(getString(dialog_->input_normal))
|| 0.0 >= strToDbl(getString(dialog_->input_large))
|| 0.0 >= strToDbl(getString(dialog_->input_larger))
|| 0.0 >= strToDbl(getString(dialog_->input_largest))
|| 0.0 >= strToDbl(getString(dialog_->input_huge))
|| 0.0 >= strToDbl(getString(dialog_->input_huger))) {
if (0.0 >= convert<double>(fl_get_input(dialog_->input_tiny))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_script))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_footnote))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_small))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_normal))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_large))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_larger))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_largest))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_huge))
|| 0.0 >= convert<double>(fl_get_input(dialog_->input_huger))) {
activate = false;
str = _("Fonts must be positive!");
} else if (strToDbl(getString(dialog_->input_tiny)) >
} else if (convert<double>(fl_get_input(dialog_->input_tiny)) >
// Fontsizes -- tiny < script < footnote etc.
strToDbl(getString(dialog_->input_script)) ||
strToDbl(getString(dialog_->input_script)) >
strToDbl(getString(dialog_->input_footnote)) ||
strToDbl(getString(dialog_->input_footnote)) >
strToDbl(getString(dialog_->input_small)) ||
strToDbl(getString(dialog_->input_small)) >
strToDbl(getString(dialog_->input_normal)) ||
strToDbl(getString(dialog_->input_normal)) >
strToDbl(getString(dialog_->input_large)) ||
strToDbl(getString(dialog_->input_large)) >
strToDbl(getString(dialog_->input_larger)) ||
strToDbl(getString(dialog_->input_larger)) >
strToDbl(getString(dialog_->input_largest)) ||
strToDbl(getString(dialog_->input_largest)) >
strToDbl(getString(dialog_->input_huge)) ||
strToDbl(getString(dialog_->input_huge)) >
strToDbl(getString(dialog_->input_huger))) {
convert<double>(fl_get_input(dialog_->input_script)) ||
convert<double>(fl_get_input(dialog_->input_script)) >
convert<double>(fl_get_input(dialog_->input_footnote)) ||
convert<double>(fl_get_input(dialog_->input_footnote)) >
convert<double>(fl_get_input(dialog_->input_small)) ||
convert<double>(fl_get_input(dialog_->input_small)) >
convert<double>(fl_get_input(dialog_->input_normal)) ||
convert<double>(fl_get_input(dialog_->input_normal)) >
convert<double>(fl_get_input(dialog_->input_large)) ||
convert<double>(fl_get_input(dialog_->input_large)) >
convert<double>(fl_get_input(dialog_->input_larger)) ||
convert<double>(fl_get_input(dialog_->input_larger)) >
convert<double>(fl_get_input(dialog_->input_largest)) ||
convert<double>(fl_get_input(dialog_->input_largest)) >
convert<double>(fl_get_input(dialog_->input_huge)) ||
convert<double>(fl_get_input(dialog_->input_huge)) >
convert<double>(fl_get_input(dialog_->input_huger))) {
activate = false;
str = _("Fonts must be input in the order Tiny > Smallest > Smaller > Small > Normal > Large > Larger > Largest > Huge > Huger.");

View File

@ -31,8 +31,6 @@ using std::string;
namespace lyx {
using support::strToInt;
namespace frontend {
typedef FormController<ControlPrint, FormView<FD_print> > base_class;
@ -128,10 +126,10 @@ void FormPrint::apply()
pp.from_page = pp.to_page = 0;
if (!getString(dialog_->input_from_page).empty()) {
// we have at least one page requested
pp.from_page = strToInt(fl_get_input(dialog_->input_from_page));
pp.from_page = convert<int>(fl_get_input(dialog_->input_from_page));
if (!getString(dialog_->input_to_page).empty()) {
// okay we have a range
pp.to_page = strToInt(fl_get_input(dialog_->input_to_page));
pp.to_page = convert<int>(fl_get_input(dialog_->input_to_page));
} // else we only print one page.
}
@ -228,18 +226,18 @@ ButtonPolicy::SMInput FormPrint::input(FL_OBJECT * ob, long)
bool const to_input = static_cast<bool>(*to);
setEnabled(dialog_->input_to_page, from_input);
if (!from_input || (to_input && strToInt(from) > strToInt(to))) {
if (!from_input || (to_input && convert<int>(from) > convert<int>(to))) {
// Invalid input. Either 'from' is empty, or 'from' > 'to'.
// Probably editting these fields, so deactivate OK/Apply until input is valid again.
activate = ButtonPolicy::SMI_INVALID;
} else if (!to_input || strToInt(from) == strToInt(to)) {
} else if (!to_input || convert<int>(from) == convert<int>(to)) {
// Valid input. Either there's only 'from' input, or 'from' == 'to'.
// Deactivate OK/Apply if odd/even selection implies no pages.
bool const odd_pages = static_cast<bool>(fl_get_button(dialog_->check_odd_pages));
bool const even_pages = static_cast<bool>(fl_get_button(dialog_->check_even_pages));
bool const odd_only = odd_pages && !even_pages;
bool const even_only = even_pages && !odd_pages;
bool const from_is_odd = static_cast<bool>(strToInt(from) % 2);
bool const from_is_odd = static_cast<bool>(convert<int>(from) % 2);
if ( (from_is_odd && even_only) || (!from_is_odd && odd_only) ) {
activate = ButtonPolicy::SMI_INVALID;
}

View File

@ -19,8 +19,8 @@
#include "frontends/lyx_gui.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/systemcall.h"
#include "lyx_forms.h"
@ -33,7 +33,6 @@ using std::string;
namespace lyx {
using support::LibFileSearch;
using support::strToDbl;
using support::OnlyPath;
using support::Systemcall;
@ -333,7 +332,7 @@ XFontStruct * xfont_loader::doLoad(LyXFont::FONT_FAMILY family,
getFontinfo(family, series, shape);
// FIXME! CHECK! Should we use 72.0 or 72.27? (Lgb)
int fsize = int((strToDbl(lyxrc.font_sizes[size]) * lyxrc.dpi *
int fsize = int((convert<double>(lyxrc.font_sizes[size]) * lyxrc.dpi *
(lyxrc.zoom/100.0)) / 72.27 + 0.5);
string font = fontinfo[family][series][shape]->getFontname(fsize);

View File

@ -1,3 +1,10 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* PreviewLoader.C (Impl): use convert<> instead of atoi,strToXXX
and friends
* GraphicsParams.h (class Params): change angle from float to double
2005-01-06 Lars Gullik Bjonnes <larsbj@gullik.net>
* PreviewLoader.C (unique_filename): tostr -> convert

View File

@ -69,7 +69,7 @@ public:
* image.
*/
/// Rotation angle.
float angle;
double angle;
};
bool operator==(Params const &, Params const &);

View File

@ -320,7 +320,7 @@ PreviewLoader::Impl::Impl(PreviewLoader & p, Buffer const & b)
: parent_(p), buffer_(b), font_scaling_factor_(0.0)
{
font_scaling_factor_ = 0.01 * lyxrc.dpi * lyxrc.zoom *
support::strToDbl(lyxrc.preview_scale_factor);
convert<double>(lyxrc.preview_scale_factor);
lyxerr[Debug::GRAPHICS] << "The font scaling factor is "
<< font_scaling_factor_ << endl;

View File

@ -1,3 +1,7 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* Several files: use convert<> instead of atoi,strToXXX and friends
2005-01-23 Angus Leeming <leeming@lyx.org>
* insetbibitem.h (bibitemWidest): declare the function.

View File

@ -25,7 +25,6 @@
#include <sstream>
using lyx::support::float_equal;
using lyx::support::strToDbl;
using std::string;
@ -54,20 +53,20 @@ bool ResizeData::no_resize() const
bool ResizeData::usingScale() const
{
return (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05));
return (!scale.empty() && !float_equal(convert<double>(scale), 0.0, 0.05));
}
bool RotationData::no_rotation() const
{
return (angle.empty() || std::abs(strToDbl(angle)) < 0.1);
return (angle.empty() || std::abs(convert<double>(angle)) < 0.1);
}
string const RotationData::adjAngle() const
{
// Ensure that angle lies in the range -360 < angle < 360
double rotAngle = strToDbl(angle);
double rotAngle = convert<double>(angle);
if (std::abs(rotAngle) > 360.0) {
rotAngle -= 360.0 * floor(rotAngle / 360.0);
return convert<string>(rotAngle);
@ -103,7 +102,7 @@ string const ResizeLatexCommand::front_impl() const
std::ostringstream os;
if (data.usingScale()) {
double const scl = strToDbl(data.scale) / 100.0;
double const scl = convert<double>(data.scale) / 100.0;
os << "\\scalebox{" << scl << "}[" << scl << "]{";
} else {
string width = "!";
@ -235,7 +234,7 @@ string const ResizeLatexOption::option_impl() const
std::ostringstream os;
if (data.usingScale()) {
double scl = strToDbl(data.scale);
double const scl = convert<double>(data.scale);
if (!float_equal(scl, 100.0, 0.05))
os << "scale=" << scl / 100.0 << ',';
return os.str();

View File

@ -28,7 +28,6 @@
#include "support/convert.h"
using lyx::support::prefixIs;
using lyx::support::strToInt;
using std::max;
using std::string;
@ -103,7 +102,7 @@ void InsetBibitem::read(Buffer const &, LyXLex & lex)
lex.printError("InsetCommand: Parse error: `$$Token'");
if (prefixIs(getContents(), key_prefix)) {
int key = strToInt(getContents().substr(key_prefix.length()));
int const key = convert<int>(getContents().substr(key_prefix.length()));
key_counter = max(key_counter, key);
}
}

View File

@ -210,7 +210,7 @@ void InsetCollapsable::getCursorPos
y = yo();
return;
}
InsetText::getCursorPos(sl, x, y);
if (status_ == Open) {
if (openinlined_)
@ -408,7 +408,7 @@ void InsetCollapsable::setLabelFont(LyXFont & font)
}
void InsetCollapsable::scroll(BufferView & bv, float sx) const
void InsetCollapsable::scroll(BufferView & bv, double sx) const
{
UpdatableInset::scroll(bv, sx);
}
@ -418,4 +418,3 @@ void InsetCollapsable::scroll(BufferView & bv, int offset) const
{
UpdatableInset::scroll(bv, offset);
}

View File

@ -73,7 +73,7 @@ public:
///
int scroll(bool recursive = true) const;
///
void scroll(BufferView & bv, float sx) const;
void scroll(BufferView & bv, double sx) const;
///
void scroll(BufferView & bv, int offset) const;
///

View File

@ -228,7 +228,7 @@ void InsetExternalParams::write(Buffer const & buffer, ostream & os) const
if (!resizedata.no_resize()) {
using support::float_equal;
double scl = support::strToDbl(resizedata.scale);
double const scl = convert<double>(resizedata.scale);
if (!float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
os << "\tscale "
@ -524,7 +524,7 @@ graphics::Params get_grfx_params(InsetExternalParams const & eparams)
gparams.scale = eparams.lyxscale;
if (eparams.clipdata.clip)
gparams.bb = eparams.clipdata.bbox;
gparams.angle = lyx::support::strToDbl(eparams.rotationdata.adjAngle());
gparams.angle = convert<double>(eparams.rotationdata.adjAngle());
switch (eparams.display) {
case external::DefaultDisplay:

View File

@ -74,6 +74,7 @@ TODO
#include "frontends/Alert.h"
#include "frontends/LyXView.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lyxalgo.h" // lyx::count
#include "support/lyxlib.h" // lyx::sum
@ -99,7 +100,6 @@ using lyx::support::GetExtension;
using lyx::support::IsFileReadable;
using lyx::support::OnlyFilename;
using lyx::support::rtrim;
using lyx::support::strToDbl;
using lyx::support::subst;
using lyx::support::Systemcall;
using lyx::support::unzipFile;
@ -299,7 +299,7 @@ string const InsetGraphics::createLatexOptions() const
options << " draft,\n";
if (params().clip)
options << " clip,\n";
double const scl = strToDbl(params().scale);
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << " scale=" << scl / 100.0
@ -316,7 +316,7 @@ string const InsetGraphics::createLatexOptions() const
// Make sure rotation angle is not very close to zero;
// a float can be effectively zero but not exactly zero.
if (!params().rotateAngle.empty()
&& !float_equal(strToDbl(params().rotateAngle), 0.0, 0.001)) {
&& !float_equal(convert<double>(params().rotateAngle), 0.0, 0.001)) {
options << " angle=" << params().rotateAngle << ",\n";
if (!params().rotateOrigin.empty()) {
options << " origin=" << params().rotateOrigin[0];
@ -405,7 +405,7 @@ string const InsetGraphics::createDocBookAttributes() const
// Right now it only works with my version of db2latex :-)
ostringstream options;
double const scl = strToDbl(params().scale);
double const scl = convert<double>(params().scale);
if (!params().scale.empty() && !float_equal(scl, 0.0, 0.05)) {
if (!float_equal(scl, 100.0, 0.05))
options << " scale=\""

View File

@ -21,6 +21,7 @@
#include "graphics/GraphicsParams.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lyxlib.h"
#include "support/lstrings.h"
@ -28,8 +29,6 @@
using lyx::support::float_equal;
using lyx::support::readBB_from_PSFile;
using lyx::support::strToDbl;
using lyx::support::strToInt;
using lyx::support::token;
using std::string;
@ -155,8 +154,8 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
os << "\tlyxscale " << lyxscale << '\n';
if (display != lyx::graphics::DefaultDisplay)
os << "\tdisplay " << lyx::graphics::displayTranslator().find(display) << '\n';
if (!scale.empty() && !float_equal(strToDbl(scale), 0.0, 0.05)) {
if (!float_equal(strToDbl(scale), 100.0, 0.05))
if (!scale.empty() && !float_equal(convert<double>(scale), 0.0, 0.05)) {
if (!float_equal(convert<double>(scale), 100.0, 0.05))
os << "\tscale " << scale << '\n';
} else {
if (!width.zero())
@ -178,7 +177,7 @@ void InsetGraphicsParams::Write(ostream & os, string const & bufpath) const
os << "\tclip\n";
if (!rotateAngle.empty()
&& !float_equal(strToDbl(rotateAngle), 0.0, 0.001))
&& !float_equal(convert<double>(rotateAngle), 0.0, 0.001))
os << "\trotateAngle " << rotateAngle << '\n';
if (!rotateOrigin.empty())
os << "\trotateOrigin " << rotateOrigin << '\n';
@ -267,7 +266,7 @@ lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
lyx::graphics::Params pars;
pars.filename = filename.absFilename();
pars.scale = lyxscale;
pars.angle = lyx::support::strToDbl(rotateAngle);
pars.angle = convert<double>(rotateAngle);
if (clip) {
pars.bb = bb;
@ -276,8 +275,9 @@ lyx::graphics::Params InsetGraphicsParams::as_grfxParams() const
string const tmp = readBB_from_PSFile(filename.absFilename());
lyxerr[Debug::GRAPHICS] << "BB_from_File: " << tmp << std::endl;
if (!tmp.empty()) {
unsigned int const bb_orig_xl = strToInt(token(tmp, ' ', 0));
unsigned int const bb_orig_yb = strToInt(token(tmp, ' ', 1));
#warning why not convert to unsigned int? (Lgb)
unsigned int const bb_orig_xl = convert<int>(token(tmp, ' ', 0));
unsigned int const bb_orig_yb = convert<int>(token(tmp, ' ', 1));
// new pars.bb values must be >= zero
if (pars.bb.xl > bb_orig_xl)

View File

@ -33,6 +33,8 @@
#include "ParagraphParameters.h"
#include "undo.h"
#include "support/convert.h"
#include "frontends/Alert.h"
#include "frontends/font_metrics.h"
#include "frontends/LyXView.h"
@ -46,8 +48,6 @@
using lyx::graphics::PreviewLoader;
using lyx::support::ltrim;
using lyx::support::strToInt;
using lyx::support::strToDbl;
using boost::shared_ptr;
@ -496,9 +496,9 @@ void InsetTabular::doDispatch(LCursor & cur, FuncRequest & cmd)
if (cmd.argument.empty())
break;
if (cmd.argument.find('.') != cmd.argument.npos)
scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
else
scroll(cur.bv(), strToInt(cmd.argument));
scroll(cur.bv(), convert<int>(cmd.argument));
break;
case LFUN_RIGHTSEL:
@ -878,7 +878,7 @@ bool InsetTabular::getStatus(LCursor & cur, FuncRequest const & cmd,
break;
case LyXTabular::SET_USEBOX:
status.setOnOff(strToInt(argument) == tabular.getUsebox(cur.idx()));
status.setOnOff(convert<int>(argument) == tabular.getUsebox(cur.idx()));
break;
case LyXTabular::SET_LTFIRSTHEAD:
@ -1496,7 +1496,7 @@ void InsetTabular::tabularFeatures(LCursor & cur,
break;
case LyXTabular::SET_USEBOX: {
LyXTabular::BoxType val = LyXTabular::BoxType(strToInt(value));
LyXTabular::BoxType val = LyXTabular::BoxType(convert<int>(value));
if (val == tabular.getUsebox(cur.idx()))
val = LyXTabular::BOX_NONE;
for (row_type i = sel_row_start; i <= sel_row_end; ++i)

View File

@ -57,7 +57,6 @@ using lyx::pos_type;
using lyx::graphics::PreviewLoader;
using lyx::support::isStrUnsignedInt;
using lyx::support::strToUnsignedInt;
using boost::bind;
using boost::ref;

View File

@ -23,14 +23,10 @@
#include "funcrequest.h"
#include "lyxtext.h"
#include "support/lstrings.h"
#include "support/convert.h"
#include <boost/assert.hpp>
using lyx::support::strToDbl;
using lyx::support::strToInt;
// An updatable inset is highly editable by definition
InsetBase::EDITABLE UpdatableInset::editable() const
@ -39,7 +35,7 @@ InsetBase::EDITABLE UpdatableInset::editable() const
}
void UpdatableInset::scroll(BufferView & bv, float s) const
void UpdatableInset::scroll(BufferView & bv, double s) const
{
if (!s) {
scx = 0;
@ -52,7 +48,7 @@ void UpdatableInset::scroll(BufferView & bv, float s) const
if (tmp_xo_ > 0 && tmp_xo_ + width() < workW)
return;
if (s > 0 && xo_ > 0)
if (s > 0.0 && xo_ > 0)
return;
scx = int(s * workW / 2);
@ -100,9 +96,9 @@ void UpdatableInset::doDispatch(LCursor & cur, FuncRequest & cmd)
case LFUN_SCROLL_INSET:
if (cmd.argument.empty()) {
if (cmd.argument.find('.') != cmd.argument.npos)
scroll(cur.bv(), static_cast<float>(strToDbl(cmd.argument)));
scroll(cur.bv(), static_cast<float>(convert<double>(cmd.argument)));
else
scroll(cur.bv(), strToInt(cmd.argument));
scroll(cur.bv(), convert<int>(cmd.argument));
cur.bv().update();
}
break;

View File

@ -40,7 +40,7 @@ protected:
/// An updatable inset could handle lyx editing commands
virtual void doDispatch(LCursor & cur, FuncRequest & cmd);
/// scrolls to absolute position in bufferview-workwidth * sx units
void scroll(BufferView &, float sx) const;
void scroll(BufferView &, double sx) const;
/// scrolls offset pixels
void scroll(BufferView &, int offset) const;
};

View File

@ -113,8 +113,6 @@ using lyx::support::Path;
using lyx::support::QuoteName;
using lyx::support::rtrim;
using lyx::support::split;
using lyx::support::strToInt;
using lyx::support::strToUnsignedInt;
using lyx::support::subst;
using lyx::support::Systemcall;
using lyx::support::token;

View File

@ -110,17 +110,17 @@ public:
/// Text that dictates the width of the indentation of indented pars
std::string parindent;
///
float parskip;
double parskip;
///
float itemsep;
double itemsep;
///
float topsep;
double topsep;
///
float bottomsep;
double bottomsep;
///
float labelbottomsep;
double labelbottomsep;
///
float parsep;
double parsep;
///
Spacing spacing;
///

View File

@ -18,6 +18,7 @@
#include "debug.h"
#include "lyxlex_pimpl.h"
#include "support/convert.h"
#include "support/lstrings.h"
using lyx::support::compare_ascii_no_case;
@ -25,8 +26,6 @@ using lyx::support::isStrDbl;
using lyx::support::isStrInt;
using lyx::support::ltrim;
using lyx::support::prefixIs;
using lyx::support::strToDbl;
using lyx::support::strToInt;
using lyx::support::subst;
using lyx::support::trim;
@ -121,20 +120,20 @@ int LyXLex::lex()
int LyXLex::getInteger() const
{
if (isStrInt(pimpl_->getString()))
return strToInt(pimpl_->getString());
return convert<int>(pimpl_->getString());
pimpl_->printError("Bad integer `$$Token'");
return -1;
}
float LyXLex::getFloat() const
double LyXLex::getFloat() const
{
// replace comma with dot in case the file was written with
// the wrong locale (should be rare, but is easy enough to
// avoid).
string str = subst(pimpl_->getString(), ",", ".");
string const str = subst(pimpl_->getString(), ",", ".");
if (isStrDbl(str))
return strToDbl(str);
return convert<double>(str);
pimpl_->printError("Bad float `$$Token'");
return -1;
}
@ -256,7 +255,7 @@ LyXLex & LyXLex::operator>>(std::string & s)
}
LyXLex & LyXLex::operator>>(float & s)
LyXLex & LyXLex::operator>>(double & s)
{
if (isOK()) {
next();

View File

@ -96,7 +96,7 @@ public:
///
bool getBool() const;
///
float getFloat() const;
double getFloat() const;
///
std::string const getString() const;
@ -131,8 +131,6 @@ public:
/// extract string
LyXLex & operator>>(std::string &);
/// extract float
LyXLex & operator>>(float &);
/// extract double
LyXLex & operator>>(double &);
/// extract integer

View File

@ -1,3 +1,8 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* math_parser.C,math_sizeinset.C: use convert<> instead of
atoi,strToXXX and friends
2005-01-20 Angus Leeming <leeming@lyx.org>
* math_spaceinset.C (validate):

View File

@ -62,12 +62,11 @@ following hack as starting point to write some macros:
#include "lyxlex.h"
#include "debug.h"
#include "support/lyxlib.h"
#include "support/convert.h"
#include <sstream>
using lyx::support::atoi;
using std::endl;
using std::fill;
@ -854,9 +853,9 @@ void Parser::parse1(MathGridInset & grid, unsigned flags,
return;
}
string arg = getArg('[', ']');
string const arg = getArg('[', ']');
if (!arg.empty())
nargs = atoi(arg);
nargs = convert<int>(arg);
}

View File

@ -16,16 +16,14 @@
#include "math_parser.h"
#include "math_streamstr.h"
#include "support/convert.h"
#include "support/std_ostream.h"
#include "support/lyxlib.h"
using lyx::support::atoi;
using std::auto_ptr;
MathSizeInset::MathSizeInset(latexkeys const * l)
: MathNestInset(1), key_(l), style_(Styles(atoi(l->extra)))
: MathNestInset(1), key_(l), style_(Styles(convert<int>(l->extra)))
{}

View File

@ -1,3 +1,24 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* tests: add some code for automatic regression testing, can be
improved or removed as we see fit
* lyxlib.h (atoi): delete func
* lstrings.[Ch] (strToInt): delete func
(strToUnsignedInt): delete func
(strToDbl): delete func
* Makefile.am: add subdir tests, delete atoi.C
* atoi.C: delete file
* convert.C: add specializations for converting to int, unsigned
int, double from string, and for converting to int and double from
char const *
* convert.h: remove commented code
2005-01-22 Angus Leeming <leeming@lyx.org>
* path.C (Path): revert the patch since the if statement has side
@ -28,7 +49,7 @@
* filetools.[Ch] (LibScriptSearch): modify the code that replaces
the $$s placeholder with a path, so that it now inserts the path
of the lyx support directory, not the scripts subdirectory.
2005-01-19 Asger Ottar Alstrup <aalstrup@laerdal.dk>
* lyxsum.C, socktools.C, tempname.C, userinfo.C: use the

View File

@ -1,5 +1,7 @@
include $(top_srcdir)/config/common.am
SUBDIRS = . tests
noinst_LTLIBRARIES = libsupport.la
CLEANFILES += path_defines.C
@ -20,7 +22,6 @@ libsupport_la_SOURCES = \
FileMonitor.h \
FileMonitor.C \
abort.C \
atoi.C \
chdir.C \
convert.C \
convert.h \

View File

@ -1,25 +0,0 @@
/**
* \file atoi.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
* \author Jean-Marc Lasgouttes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include "support/lyxlib.h"
#include <cstdlib>
#ifndef CXX_GLOBAL_CSTD
using std::atoi;
#endif
int lyx::support::atoi(std::string const & nstr)
{
return ::atoi(nstr.c_str());
}

View File

@ -83,3 +83,38 @@ string convert<string>(double d)
{
return lexical_cast<string>(d);
}
template<>
int convert<int>(string const s)
{
return strtol(s.c_str(), 0, 10);
}
template<>
unsigned int convert<unsigned int>(string const s)
{
return strtoul(s.c_str(), 0, 10);
}
template<>
double convert<double>(string const s)
{
return strtod(s.c_str(), 0);
}
template<>
int convert<int>(char const * cptr)
{
return strtol(cptr, 0, 10);
}
template<>
double convert<double>(char const * cptr)
{
return strtod(cptr, 0);
}

View File

@ -16,21 +16,7 @@
#ifndef CONVERT_H
#define CONVERT_H
#if 0
#include <boost/static_assert.hpp>
// Commented out since BOOST_STATIC_ASSERT does not work with gcc 4.0
template <class Target, class Source>
Target convert(Source arg)
{
// We use a static assert here since we want all instances of
// this template to be specializations.
BOOST_STATIC_ASSERT(sizeof(bool) == 0);
return Target();
}
#else
template <class Target, class Source>
Target convert(Source arg);
#endif
#endif

View File

@ -37,7 +37,6 @@ using std::string;
using std::vector;
#ifndef CXX_GLOBAL_CSTD
using std::atof;
using std::isdigit;
using std::tolower;
using std::toupper;
@ -158,32 +157,6 @@ bool isStrUnsignedInt(string const & str)
}
int strToInt(string const & str)
{
if (isStrInt(str)) {
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
// Do the conversion proper.
return atoi(tmpstr);
} else {
return 0;
}
}
unsigned int strToUnsignedInt(string const & str)
{
if (isStrUnsignedInt(str)) {
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
// Do the conversion proper.
return atoi(tmpstr);
} else {
return 0;
}
}
bool isStrDbl(string const & str)
{
if (str.empty()) return false;
@ -214,19 +187,6 @@ bool isStrDbl(string const & str)
}
double strToDbl(string const & str)
{
if (isStrDbl(str)) {
// Remove leading and trailing white space chars.
string const tmpstr = trim(str);
// Do the conversion proper.
return ::atof(tmpstr.c_str());
} else {
return 0.0;
}
}
char lowercase(char c)
{
return char(tolower(c));

View File

@ -60,18 +60,9 @@ bool isStrInt(std::string const & str);
/// does the std::string represent an unsigned integer value ?
bool isStrUnsignedInt(std::string const & str);
///
int strToInt(std::string const & str);
/// convert string to an unsigned integer
unsigned int strToUnsignedInt(std::string const & str);
///
bool isStrDbl(std::string const & str);
///
double strToDbl(std::string const & str);
///
char lowercase(char c);

View File

@ -46,8 +46,6 @@ bool putenv(std::string const & varname, std::string const & value);
int unlink(std::string const & file);
/// remove the given directory
int rmdir(std::string const & file);
/// convert the given string to an integer
int atoi(std::string const & nstr);
/// (securely) create a temporary file in the given dir with the given prefix
std::string const tempName(std::string const & dir = std::string(),
std::string const & mask = std::string());

View File

@ -0,0 +1,6 @@
Makefile
Makefile.in
.deps
.libs
convert
lstrings

View File

@ -0,0 +1,26 @@
include $(top_srcdir)/config/common.am
TESTS = \
test_convert \
test_lstrings
check_PROGRAMS = \
convert \
lstrings
AM_CPPFLAGS = $(BOOST_INCLUDES)
convert_LDADD = ../convert.o
convert_SOURCES = \
convert.C \
boost.C
lstrings_LDADD = ../lstrings.o
lstrings_SOURCES = \
lstrings.C \
boost.C
regfiles: ${check_PROGRAMS}
for all in ${check_PROGRAMS} ; do \
./$$all > regfiles/$$all ; \
done

33
src/support/tests/boost.C Normal file
View File

@ -0,0 +1,33 @@
/**
* \file boost.C
* This file is part of LyX, the document processor.
* Licence details can be found in the file COPYING.
*
* \author Lars Gullik Bjønnes
*
* Full author contact details are available in file CREDITS.
*/
#include <config.h>
#include <boost/assert.hpp>
#include <cstdlib>
#include <exception>
namespace boost {
void throw_exception(std::exception const & /*e*/)
{
BOOST_ASSERT(false);
}
void assertion_failed(char const * /*expr*/, char const * /*function*/,
char const * /*file*/, long /*line*/)
{
::abort();
}
}

View File

@ -0,0 +1,86 @@
#include <config.h>
#include "../convert.h"
#include <iostream>
using namespace std;
void convert_int()
{
cout << convert<int>("123") << '\n'
<< convert<int>(" 123") << '\n'
<< convert<int>("123 ") << '\n'
<< convert<int>(" 123 ") << '\n'
<< convert<int>("123 123") << '\n'
<< convert<int>(" 123 123") << '\n'
<< convert<int>("123 123 ") << '\n'
<< convert<int>(" 123 123 ") << '\n'
<< convert<int>("-123") << '\n'
<< convert<int>(" -123") << '\n'
<< convert<int>("-123 ") << '\n'
<< convert<int>(" -123 ") << '\n'
<< convert<int>("-123 123") << '\n'
<< convert<int>(" -123 123") << '\n'
<< convert<int>("-123 123 ") << '\n'
<< convert<int>(" -123 123 ") << '\n'
<< convert<int>("") << '\n'
<< convert<int>("abc") << '\n'
<< convert<int>(" abc") << '\n'
<< convert<int>("abc ") << '\n'
<< convert<int>(" abc ") << '\n'
<< convert<int>(" 123 abc") << '\n'
<< convert<int>("123 abc ") << '\n'
<< convert<int>(" 123 abc ") << '\n'
<< convert<int>("123 abc") << endl;
}
void convert_unsigned()
{
cout << convert<unsigned int>(string("123")) << '\n'
<< convert<unsigned int>(string(" 123")) << '\n'
<< convert<unsigned int>(string("123 ")) << '\n'
<< convert<unsigned int>(string(" 123 ")) << '\n'
<< convert<unsigned int>(string("123 123")) << '\n'
<< convert<unsigned int>(string(" 123 123")) << '\n'
<< convert<unsigned int>(string("123 123 ")) << '\n'
<< convert<unsigned int>(string(" 123 123 ")) << '\n'
<< convert<unsigned int>(string()) << '\n'
<< convert<unsigned int>(string("abc")) << '\n'
<< convert<unsigned int>(string(" abc")) << '\n'
<< convert<unsigned int>(string("abc ")) << '\n'
<< convert<unsigned int>(string(" abc ")) << '\n'
<< convert<unsigned int>(string(" 123 abc")) << '\n'
<< convert<unsigned int>(string("123 abc ")) << '\n'
<< convert<unsigned int>(string(" 123 abc ")) << '\n'
<< convert<unsigned int>(string("123 abc")) << endl;
}
void convert_string()
{
cout << convert<string>(123) << '\n'
<< convert<string>(4294967173u) << '\n'
<< convert<string>(true) << '\n'
<< convert<string>(false) << '\n'
<< convert<string>('a') << '\n'
<< convert<string>(1.0) << '\n'
<< convert<string>(1.1) << endl;
}
int main()
{
convert_int();
convert_unsigned();
convert_string();
}

View File

@ -0,0 +1,25 @@
#include "../lstrings.h"
#include <iostream>
using namespace lyx::support;
using namespace std;
void test_lowercase()
{
cout << lowercase('A') << endl;
cout << lowercase("AlLe") << endl;
}
void test_uppercase()
{
cout << uppercase('a') << endl;
cout << uppercase("AlLe") << endl;
}
int main()
{
test_lowercase();
test_uppercase();
}

View File

@ -0,0 +1,49 @@
123
123
123
123
123
123
123
123
-123
-123
-123
-123
-123
-123
-123
-123
0
0
0
0
0
123
123
123
123
123
123
123
123
123
123
123
123
0
0
0
0
0
123
123
123
123
123
4294967173
true
false
a
1
1.1

View File

@ -0,0 +1,4 @@
a
alle
A
ALLE

7
src/support/tests/test_convert Executable file
View File

@ -0,0 +1,7 @@
#!/bin/bash
regfile=`cat regfiles/convert`
output=`./convert`
test "$regfile" = "$output"
exit $?

View File

@ -0,0 +1,7 @@
#!/bin/bash
regfile=`cat regfiles/lstrings`
output=`./lstrings`
test "$regfile" = "$output"
exit $?

View File

@ -37,7 +37,6 @@
using lyx::support::ltrim;
using lyx::support::prefixIs;
using lyx::support::rtrim;
using lyx::support::strToInt;
using lyx::support::suffixIs;
using boost::shared_ptr;
@ -249,7 +248,7 @@ bool getTokenValue(string const & str, char const * token, int & num)
num = 0;
if (!getTokenValue(str, token, tmp))
return false;
num = strToInt(tmp);
num = convert<int>(tmp);
return true;
}

View File

@ -1,3 +1,9 @@
2005-01-27 Lars Gullik Bjonnes <larsbj@gullik.net>
* Spacing (set): take double instead of float
* tex2lyx.C: convert stuff
2005-01-11 Jean-Marc Lasgouttes <lasgouttes@lyx.org>
* Spacing.h: remove unused parameters

View File

@ -29,7 +29,7 @@ public:
Default
};
///
void set(Spacing::Space, float = 1.0) {}
void set(Spacing::Space, double = 1.0) {}
///
void set(Spacing::Space, std::string const &) {}
};

View File

@ -17,6 +17,8 @@
#include "debug.h"
#include "lyxtextclass.h"
#include "support/convert.h"
#include "support/filetools.h"
#include "support/lstrings.h"
#include "support/lyxlib.h"
@ -50,7 +52,6 @@ using std::map;
using lyx::support::isStrUnsignedInt;
using lyx::support::ltrim;
using lyx::support::rtrim;
using lyx::support::strToUnsignedInt;
using lyx::support::IsFileReadable;
using lyx::support::IsFileWriteable;
@ -137,7 +138,7 @@ void add_known_command(string const & command, string const & o1,
string const opt1 = rtrim(ltrim(o1, "["), "]");
if (isStrUnsignedInt(opt1)) {
// The command has arguments
nargs = strToUnsignedInt(opt1);
nargs = convert<unsigned int>(opt1);
if (nargs > 0 && o2) {
// The first argument is optional
arguments.push_back(optional);

View File

@ -70,8 +70,6 @@ using lyx::cap::pasteSelection;
using lyx::cap::replaceSelection;
using lyx::support::isStrUnsignedInt;
using lyx::support::strToUnsignedInt;
using lyx::support::atoi;
using lyx::support::token;
using std::endl;
@ -886,7 +884,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
#warning FIXME Check if the arg is in the domain of available selections.
#endif
if (isStrUnsignedInt(cmd.argument))
pasteSelection(cur, strToUnsignedInt(cmd.argument));
pasteSelection(cur, convert<unsigned int>(cmd.argument));
else
pasteSelection(cur, 0);
cur.clearSelection(); // bug 393
@ -1331,7 +1329,7 @@ void LyXText::dispatch(LCursor & cur, FuncRequest & cmd)
else {
string s = cmd.argument;
string const s1 = token(s, ' ', 1);
int const nargs = s1.empty() ? 0 : atoi(s1);
int const nargs = s1.empty() ? 0 : convert<int>(s1);
string const s2 = token(s, ' ', 2);
string const type = s2.empty() ? "newcommand" : s2;
cur.insert(new MathMacroTemplate(token(s, ' ', 0), nargs, s2));

View File

@ -17,6 +17,7 @@
#include "lengthcommon.h"
#include "lyxtext.h"
#include "support/convert.h"
#include "support/lstrings.h"
using lyx::support::compare;
@ -24,7 +25,6 @@ using lyx::support::isStrDbl;
using lyx::support::ltrim;
using lyx::support::prefixIs;
using lyx::support::rtrim;
using lyx::support::strToDbl;
using std::string;
@ -117,7 +117,7 @@ char nextToken(string & data)
lyx_advance(data, i);
if (isStrDbl(buffer)) {
number[number_index] = strToDbl(buffer);
number[number_index] = convert<double>(buffer);
++number_index;
return 'n';
}
@ -388,7 +388,7 @@ VSpace::VSpace(string const & data)
// without units in added_space_top/bottom.
// Let unit default to centimeters here.
kind_ = LENGTH;
len_ = LyXGlueLength(LyXLength(strToDbl(input), LyXLength::CM));
len_ = LyXGlueLength(LyXLength(convert<double>(input), LyXLength::CM));
}
}