units.cpp revision 87dacccf64bee38af81afde687844a37b57b5b9a
/*
* Inkscape Units
*
* Authors:
* Matthew Petroff <matthew@mpetroff.net>
*
* Copyright (C) 2013 Matthew Petroff
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cmath>
#include <cerrno>
#include <iomanip>
#include <glib.h>
#include <glibmm/fileutils.h>
#include "path-prefix.h"
#include "streq.h"
namespace
{
#define MAKE_UNIT_CODE(a, b) \
((((unsigned)(a) & 0xdf) << 8) | ((unsigned)(b) & 0xdf))
enum UnitCode {
};
// TODO: convert to constexpr in C++11, so that the above constants can be eliminated
inline unsigned make_unit_code(char a, char b) {
// this should work without the casts, but let's be 100% sure
// also ensure that the codes are in lowercase
return MAKE_UNIT_CODE(a,b);
}
inline unsigned make_unit_code(char const *str) {
}
unsigned const svg_length_lookup[] = {
0,
};
// maps unit codes obtained from their abbreviations to their SVGLength unit indexes
{
}
return umap;
}
/** A std::map that gives the data type value for the string version.
* @todo consider hiding map behind hasFoo() and getFoo() type functions. */
{
// Note that code was not yet handling LINEAR_SCALED, TIME, QTY and NONE
return tmap;
}
} // namespace
namespace Inkscape {
namespace Util {
{
public:
virtual ~UnitParser() {}
protected:
public:
bool primary;
bool skip;
};
primary(false),
skip(false)
{
}
#define BUFSIZE (255)
factor(1.0),
name(),
name_plural(),
abbr(),
{
}
double factor,
{
g_return_if_fail(factor <= 0);
}
{
*this = Unit();
}
int Unit::defaultDigits() const
{
if (factor_digits < 0) {
g_warning("factor_digits < 0 - returning 0");
factor_digits = 0;
}
return factor_digits;
}
{
// Percentages
return true;
}
// Other units with same type
return true;
}
// Different, incompatible types
return false;
}
{
static UnitTable unit_table;
}
{
}
{
if (u != unit_code_lookup.end()) {
return u->second;
}
return 0;
}
{
}
{
{
}
}
{
if (primary) {
}
}
{
return *f->second;
}
return _empty_unit;
}
{
}
{
return _empty_unit;
}
return *f->second;
}
return _empty_unit;
}
{
// Extract value
double value = 0;
Glib::RefPtr<Glib::Regex> value_regex = Glib::Regex::create("[-+]*[\\d+]*[\\.,]*[\\d+]*[eE]*[-+]*\\d+");
}
// Extract unit abbreviation
}
return qty;
}
{
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];
}
UnitParser uparser(this);
try {
return false;
} catch (Glib::MarkupError const &e) {
return false;
}
return true;
}
g_warning("UnitTable::save(): not implemented");
return true;
}
{
if (name == "unit") {
// reset for next use
primary = false;
skip = false;
} else {
skip = true;
}
}
}
}
}
{
if (element == "name") {
} else if (element == "plural") {
} else if (element == "abbr") {
} else if (element == "factor") {
// TODO make sure we use the right conversion
} else if (element == "description") {
}
}
{
}
}
{
quantity = q;
}
{
quantity = q;
}
{
quantity = q;
}
{
return unit->compatibleWith(u);
}
{
return compatibleWith(u.c_str());
}
bool Quantity::compatibleWith(char const *u) const
{
}
{
}
{
}
{
}
}
}
}
{
// Percentage
}
// Incompatible units
return -1;
}
// Compatible units
}
{
}
{
}
{
}
{
}
{
g_warning("Incompatible units");
return false;
}
}
{
}
} // 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 :