units.cpp revision bc7146ab834b1a76956e78c5f74697898afa2ade
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath>
#include <cerrno>
#include <glib.h>
#include "io/simple-sax.h"
#include "path-prefix.h"
#include "streq.h"
namespace
{
/**
* A std::map that gives the data type value for the string version.
*
* Note that we'd normally not return a reference to an internal version, but
* for this constant case it allows us to check against getTypeMappings().end().
*/
/** @todo consider hiding map behind hasFoo() and getFoo() type functions.*/
{
static bool init = false;
if (!init)
{
init = true;
// Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE
}
return typeMap;
}
} // namespace
namespace Inkscape {
namespace Util {
{
public:
virtual ~UnitsSAXHandler() {}
bool primary;
bool skip;
};
primary(0),
skip(0),
unit()
{
}
#define BUFSIZE (255)
factor(1.0),
name(),
name_plural(),
abbr(),
{
}
double factor,
{
}
{
*this = Unit();
}
int Unit::defaultDigits() const {
if (factor_digits < 0) {
g_warning("factor_digits < 0 - returning 0");
factor_digits = 0;
}
return factor_digits;
}
{
// if we swich to the xml file, don't forget to force locale to 'C'
}
{
}
}
if (primary) {
}
}
} else {
return Unit();
}
}
bool deleted = false;
// Cannot delete the primary unit type since it's
// used for conversions
deleted = true;
}
}
return deleted;
}
{
}
{
}
}
return submap;
}
{
return _primary_unit[type];
}
{
// Open file for reading
if (f == NULL) {
g_warning("Could not open units file '%s': %s\n",
return false;
}
/** @todo fix this to use C++ means and explicit locale to avoid need to change. */
// bypass current locale in order to make
// sscanf read floats with '.' as a separator
// set locale to 'C' and keep old locale
double factor = 0.0;
int nchars = 0;
// locale is set to C, scanning %lf should work _everywhere_
/** @todo address %15n, which causes a warning: */
{
// Skip the line - doesn't appear to be valid
continue;
}
// insert into _unit_map
{
continue;
}
// if primary is 'Y', list this unit as a primary
}
// set back the saved locale
g_free (old_locale);
// close file
if (fclose(f) != 0) {
return false;
}
return true;
}
UnitsSAXHandler handler(this);
if ( result != 0 ) {
// perhaps
return false;
}
return true;
}
// open file for writing
if (f == NULL) {
return false;
}
// write out header
// foreach item in _unit_map, sorted alphabetically by type and then unit name
// sprintf a line
// name
// name_plural
// abbr
// type
// factor
// PRI - if listed in primary unit table, 'Y', else 'N'
// description
// write line to the file
// close file
if (fclose(f) != 0) {
return false;
}
return true;
}
{
// reset for next use
primary = false;
skip = false;
for ( int i = 0; attrs[i]; i += 2 ) {
{
} else {
skip = true;
}
}
}
}
}
{
// TODO make sure we use the right conversion
if (!skip) {
}
}
}
} // namespace Util
} // namespace Inkscape
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :