/*
* 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 <iostream>
#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);
}
}
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)
{
}
factor(1.0),
name(),
name_plural(),
abbr(),
{
}
double factor,
{
g_return_if_fail(factor <= 0);
}
{
*this = Unit();
}
{
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;
}
{
}
{
}
{
if (u != unit_code_lookup.end()) {
return u->second;
}
return 0;
}
{
// Percentage
}
// Incompatible units
return -1;
}
// Compatible units
}
{
}
{
}
{
}
{
{
}
}
{
if (primary) {
}
}
{
return &(*f->second);
}
return &_empty_unit;
}
{
}
{
return &_empty_unit;
}
return &(*f->second);
}
return &_empty_unit;
}
{
// unit found!
break;
}
}
++cit;
}
} else {
}
}
{
// Extract value
double value = 0;
Glib::RefPtr<Glib::Regex> value_regex = Glib::Regex::create("[-+]*[\\d+]*[\\.,]*[\\d+]*[eE]*[-+]*\\d+");
}
// Extract unit abbreviation
}
return qty;
}
/* UNSAFE while passing around pointers to the Unit objects in this table
bool UnitTable::deleteUnit(Unit const &u)
{
bool deleted = false;
// Cannot delete the primary unit type since it's
// used for conversions
if (u.abbr != _primary_unit[u.type]) {
UnitCodeMap::iterator iter = _unit_map.find(make_unit_code(u.abbr.c_str()));
if (iter != _unit_map.end()) {
delete (*iter).second;
_unit_map.erase(iter);
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;
}
/*
bool UnitTable::save(std::string const &filename) {
g_warning("UnitTable::save(): not implemented");
return false;
}
*/
{
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") {
}
}
{
}
}
: unit(u)
, quantity(q)
{
}
, quantity(q)
{
}
, quantity(q)
{
}
{
return unit->compatibleWith(u);
}
{
return compatibleWith(u.c_str());
}
{
}
{
}
{
}
{
}
}
}
}
{
}
{
}
{
}
{
}
{
}
{
g_warning("Incompatible units");
return false;
}
}
{
/** \fixme This is overly strict. I think we should change this to:
if (unit->type != other.unit->type) {
g_warning("Incompatible units");
return false;
}
return are_near(quantity, other.value(unit));
*/
}
} // 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 :