summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Leske <sebastian.leske@sleske.name>2015-11-12 18:10:36 +0100
committerSebastian Leske <sebastian.leske@sleske.name>2015-11-14 00:34:06 +0100
commitb1c61538efd863473ce1fa1b3a8effd59b48e219 (patch)
tree394a225536559b0dbb101199a032344e11e7658c
parent655d54922f552ffc493ef5f24d8351ed21d25c0a (diff)
downloadnavit-b1c61538efd863473ce1fa1b3a8effd59b48e219.tar.gz
Refactor:Add comments and #defines for relative attribute values.
-rw-r--r--navit/attr.c12
-rw-r--r--navit/attr.h21
-rw-r--r--navit/attr_def.h10
3 files changed, 26 insertions, 17 deletions
diff --git a/navit/attr.c b/navit/attr.c
index 187299c5d..a4e38f09e 100644
--- a/navit/attr.c
+++ b/navit/attr.c
@@ -249,17 +249,15 @@ attr_new_from_text(const char *name, const char *value)
ret->u.num=0;
}
}
- /* Absolute values are from -0x40000000 - 0x40000000, with 0x0 being 0 (who would have thought that?)
- Relative values are from 0x40000001 - 0x80000000, with 0x60000000 being 0 */
if (value_is_relative) {
- if ((ret->u.num > 0x20000000) || (ret->u.num < -0x1FFFFFFF)) {
- dbg(lvl_error, "Relative possibly-relative attribute with invalid value %li\n", ret->u.num);
+ if ((ret->u.num > ATTR_REL_MAXREL) || (ret->u.num < ATTR_REL_MINREL)) {
+ dbg(lvl_error, "Relative possibly-relative attribute with value out of range: %li\n", ret->u.num);
}
- ret->u.num += 0x60000000;
+ ret->u.num += ATTR_REL_RELSHIFT;
} else {
- if ((ret->u.num > 0x40000000) || (ret->u.num < -0x40000000)) {
- dbg(lvl_error, "Non-relative possibly-relative attribute with invalid value %li\n", ret->u.num);
+ if ((ret->u.num > ATTR_REL_MAXABS) || (ret->u.num < ATTR_REL_MINABS)) {
+ dbg(lvl_error, "Non-relative possibly-relative attribute with value out of range: %li\n", ret->u.num);
}
}
break;
diff --git a/navit/attr.h b/navit/attr.h
index 6835f6ef2..27b37be60 100644
--- a/navit/attr.h
+++ b/navit/attr.h
@@ -97,9 +97,24 @@ enum attr_format {
#define AF_DG_EXPLOSIVE (1<<2)
#define AF_DG_FLAMMABLE (1<<3)
-/* Values for attributes that could carry relative values */
-#define ATTR_REL_MAXABS 0x40000000
-#define ATTR_REL_RELSHIFT 0x60000000
+/*
+ * Values for attributes that could carry relative values.
+ * Some attributes allow both absolute and relative values. The value for these
+ * attributes is stored as an int. Absolute values are stored as-is, relative
+ * values are stored shifted by adding ATTR_REL_RELSHIFT.
+ */
+/** Minimum value for an absolute attribute value. */
+#define ATTR_REL_MINABS -0x40000000
+/** Maximum value for an absolute attribute value. */
+#define ATTR_REL_MAXABS 0x40000000
+/** Minimum value for an relative attribute value (without value shift). */
+#define ATTR_REL_MINREL -0x1FFFFFFF
+/** Maximum value for an relative attribute value (without value shift). */
+#define ATTR_REL_MAXREL 0x20000000
+/**
+ * Value shift for relative values. This value is added to an attribute values to indicate
+ * a relative value. */
+#define ATTR_REL_RELSHIFT 0x60000000
/** Indicates whether a position is valid **/
enum attr_position_valid {
diff --git a/navit/attr_def.h b/navit/attr_def.h
index 85c9fe908..2b945226c 100644
--- a/navit/attr_def.h
+++ b/navit/attr_def.h
@@ -195,13 +195,9 @@ ATTR(turn_around_penalty2)
ATTR(autozoom_max)
ATTR(nav_status)
ATTR2(0x00027500,type_rel_abs_begin)
-/* These attributes are int that can either hold relative *
- * or absolute values. A relative value is indicated by *
- * adding 0x60000000. *
- * *
- * The range of valid absolute values is -0x40000000 to *
- * 0x40000000, the range of relative values is from *
- * -0x20000000 to 0x20000000. */
+/* These attributes are int that can either hold relative or absolute values. See the
+ * documentation of ATTR_REL_RELSHIFT for details.
+ */
ATTR(h)
ATTR(w)
ATTR(x)