[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 05/08: [troff]: Refactor `get_value` member functions.
From: |
G. Branden Robinson |
Subject: |
[groff] 05/08: [troff]: Refactor `get_value` member functions. |
Date: |
Thu, 29 Jul 2021 05:29:29 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 58409e62ed8bf98ab6e7abad108797959465317a
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Jul 29 10:00:21 2021 +1000
[troff]: Refactor `get_value` member functions.
Given their names and popular "getter/setter" paradigms from many OO
languages, the return type is misleading. Change it from `int` to
`bool` since it returns only a success/failure status and modifies an
argument (passed by reference) to deliver the requested data.
* src/roff/troff/reg.h (reg, variable_reg):
* src/roff/troff/div.cpp (page_offset_reg, page_length_reg,
vertical_position_reg, high_water_mark_reg, distance_to_next_trap_reg,
page_number_reg, no_space_mode_reg):
* src/roff/troff/env.cpp (int_env_reg, vunits_env_reg, hunits_env_reg,
horizontal_place_reg):
* src/roff/troff/input.cpp (writable_lineno_reg):
* src/roff/troff/reg.cpp (reg, number_reg, variable_reg): Update class
and member function definitions to reflect the new type. Update
member function definitions to return appropriate Boolean literals
instead of 0 and 1.
---
ChangeLog | 21 +++++++++++++++++++
src/roff/troff/div.cpp | 52 ++++++++++++++++++++++++------------------------
src/roff/troff/env.cpp | 24 +++++++++++-----------
src/roff/troff/input.cpp | 8 ++++----
src/roff/troff/reg.cpp | 14 ++++++-------
src/roff/troff/reg.h | 6 +++---
6 files changed, 73 insertions(+), 52 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index b4e1e12..34abd4d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2021-07-29 G. Branden Robinson <g.branden.robinson@gmail.com>
+
+ [troff]: Refactor `get_value` member functions. Given their
+ names and popular "getter/setter" paradigms from many OO
+ languages, the return type is misleading. Change it from `int`
+ to `bool` since it returns only a success/failure status and
+ modifies an argument (passed by reference) to deliver the
+ requested data.
+
+ * src/roff/troff/reg.h (reg, variable_reg):
+ * src/roff/troff/div.cpp (page_offset_reg, page_length_reg,
+ vertical_position_reg, high_water_mark_reg,
+ distance_to_next_trap_reg, page_number_reg, no_space_mode_reg):
+ * src/roff/troff/env.cpp (int_env_reg, vunits_env_reg,
+ hunits_env_reg, horizontal_place_reg):
+ * src/roff/troff/input.cpp (writable_lineno_reg):
+ * src/roff/troff/reg.cpp (reg, number_reg, variable_reg): Update
+ class and member function definitions to reflect the new type.
+ Update member function definitions to return appropriate Boolean
+ literals instead of 0 and 1.
+
2021-07-28 G. Branden Robinson <g.branden.robinson@gmail.com>
[grohtml]: Fix Savannah #60981. Refactor device description
diff --git a/src/roff/troff/div.cpp b/src/roff/troff/div.cpp
index 51a4a92..88d0d1a 100644
--- a/src/roff/troff/div.cpp
+++ b/src/roff/troff/div.cpp
@@ -956,14 +956,14 @@ void vertical_position_traps()
class page_offset_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-
-int page_offset_reg::get_value(units *res)
+
+bool page_offset_reg::get_value(units *res)
{
*res = topdiv->get_page_offset().to_units();
- return 1;
+ return true;
}
const char *page_offset_reg::get_string()
@@ -973,14 +973,14 @@ const char *page_offset_reg::get_string()
class page_length_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-
-int page_length_reg::get_value(units *res)
+
+bool page_length_reg::get_value(units *res)
{
*res = topdiv->get_page_length().to_units();
- return 1;
+ return true;
}
const char *page_length_reg::get_string()
@@ -990,17 +990,17 @@ const char *page_length_reg::get_string()
class vertical_position_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-
-int vertical_position_reg::get_value(units *res)
+
+bool vertical_position_reg::get_value(units *res)
{
if (curdiv == topdiv && topdiv->before_first_page)
*res = -1;
else
*res = curdiv->get_vertical_position().to_units();
- return 1;
+ return true;
}
const char *vertical_position_reg::get_string()
@@ -1013,14 +1013,14 @@ const char *vertical_position_reg::get_string()
class high_water_mark_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-
-int high_water_mark_reg::get_value(units *res)
+
+bool high_water_mark_reg::get_value(units *res)
{
*res = curdiv->get_high_water_mark().to_units();
- return 1;
+ return true;
}
const char *high_water_mark_reg::get_string()
@@ -1030,14 +1030,14 @@ const char *high_water_mark_reg::get_string()
class distance_to_next_trap_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-
-int distance_to_next_trap_reg::get_value(units *res)
+
+bool distance_to_next_trap_reg::get_value(units *res)
{
*res = curdiv->distance_to_next_trap().to_units();
- return 1;
+ return true;
}
const char *distance_to_next_trap_reg::get_string()
@@ -1058,7 +1058,7 @@ const char *diversion_name_reg::get_string()
class page_number_reg : public general_reg {
public:
page_number_reg();
- int get_value(units *);
+ bool get_value(units *);
void set_value(units);
};
@@ -1071,10 +1071,10 @@ void page_number_reg::set_value(units n)
topdiv->set_page_number(n);
}
-int page_number_reg::get_value(units *res)
+bool page_number_reg::get_value(units *res)
{
*res = topdiv->get_page_number();
- return 1;
+ return true;
}
class next_page_number_reg : public reg {
@@ -1139,14 +1139,14 @@ void nl_reg::set_value(units n)
class no_space_mode_reg : public reg {
public:
- int get_value(units *);
+ bool get_value(units *);
const char *get_string();
};
-int no_space_mode_reg::get_value(units *val)
+bool no_space_mode_reg::get_value(units *val)
{
*val = curdiv->no_space_mode;
- return 1;
+ return true;
}
const char *no_space_mode_reg::get_string()
diff --git a/src/roff/troff/env.cpp b/src/roff/troff/env.cpp
index 5becd8c..d9b15f8 100644
--- a/src/roff/troff/env.cpp
+++ b/src/roff/troff/env.cpp
@@ -3010,7 +3010,7 @@ class int_env_reg : public reg {
public:
int_env_reg(INT_FUNCP);
const char *get_string();
- int get_value(units *val);
+ bool get_value(units *val);
};
class vunits_env_reg : public reg {
@@ -3018,7 +3018,7 @@ class vunits_env_reg : public reg {
public:
vunits_env_reg(VUNITS_FUNCP f);
const char *get_string();
- int get_value(units *val);
+ bool get_value(units *val);
};
@@ -3027,7 +3027,7 @@ class hunits_env_reg : public reg {
public:
hunits_env_reg(HUNITS_FUNCP f);
const char *get_string();
- int get_value(units *val);
+ bool get_value(units *val);
};
class string_env_reg : public reg {
@@ -3041,10 +3041,10 @@ int_env_reg::int_env_reg(INT_FUNCP f) : func(f)
{
}
-int int_env_reg::get_value(units *val)
+bool int_env_reg::get_value(units *val)
{
*val = (curenv->*func)();
- return 1;
+ return true;
}
const char *int_env_reg::get_string()
@@ -3056,10 +3056,10 @@ vunits_env_reg::vunits_env_reg(VUNITS_FUNCP f) : func(f)
{
}
-int vunits_env_reg::get_value(units *val)
+bool vunits_env_reg::get_value(units *val)
{
*val = (curenv->*func)().to_units();
- return 1;
+ return true;
}
const char *vunits_env_reg::get_string()
@@ -3071,10 +3071,10 @@ hunits_env_reg::hunits_env_reg(HUNITS_FUNCP f) : func(f)
{
}
-int hunits_env_reg::get_value(units *val)
+bool hunits_env_reg::get_value(units *val)
{
*val = (curenv->*func)().to_units();
- return 1;
+ return true;
}
const char *hunits_env_reg::get_string()
@@ -3094,7 +3094,7 @@ const char *string_env_reg::get_string()
class horizontal_place_reg : public general_reg {
public:
horizontal_place_reg();
- int get_value(units *);
+ bool get_value(units *);
void set_value(units);
};
@@ -3102,10 +3102,10 @@ horizontal_place_reg::horizontal_place_reg()
{
}
-int horizontal_place_reg::get_value(units *res)
+bool horizontal_place_reg::get_value(units *res)
{
*res = curenv->get_input_line_position().to_units();
- return 1;
+ return true;
}
void horizontal_place_reg::set_value(units n)
diff --git a/src/roff/troff/input.cpp b/src/roff/troff/input.cpp
index 9ae7650..11514da 100644
--- a/src/roff/troff/input.cpp
+++ b/src/roff/troff/input.cpp
@@ -7427,21 +7427,21 @@ class writable_lineno_reg : public general_reg {
public:
writable_lineno_reg();
void set_value(units);
- int get_value(units *);
+ bool get_value(units *);
};
writable_lineno_reg::writable_lineno_reg()
{
}
-int writable_lineno_reg::get_value(units *res)
+bool writable_lineno_reg::get_value(units *res)
{
int line;
const char *file;
if (!input_stack::get_location(0, &file, &line))
- return 0;
+ return false;
*res = line;
- return 1;
+ return true;
}
void writable_lineno_reg::set_value(units n)
diff --git a/src/roff/troff/reg.cpp b/src/roff/troff/reg.cpp
index 4c2bf6c..39c5f6f 100644
--- a/src/roff/troff/reg.cpp
+++ b/src/roff/troff/reg.cpp
@@ -25,9 +25,9 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
object_dictionary number_reg_dictionary(101);
-int reg::get_value(units * /*d*/)
+bool reg::get_value(units * /*d*/)
{
- return 0;
+ return false;
}
void reg::increment()
@@ -265,7 +265,7 @@ class number_reg : public general_reg {
units value;
public:
number_reg();
- int get_value(units *);
+ bool get_value(units *);
void set_value(units);
};
@@ -273,10 +273,10 @@ number_reg::number_reg() : value(0)
{
}
-int number_reg::get_value(units *res)
+bool number_reg::get_value(units *res)
{
*res = value;
- return 1;
+ return true;
}
void number_reg::set_value(units n)
@@ -293,10 +293,10 @@ void variable_reg::set_value(units n)
*ptr = n;
}
-int variable_reg::get_value(units *res)
+bool variable_reg::get_value(units *res)
{
*res = *ptr;
- return 1;
+ return true;
}
void define_number_reg()
diff --git a/src/roff/troff/reg.h b/src/roff/troff/reg.h
index ef91e5d..34ded8c 100644
--- a/src/roff/troff/reg.h
+++ b/src/roff/troff/reg.h
@@ -21,7 +21,7 @@ along with this program. If not, see
<http://www.gnu.org/licenses/>. */
class reg : public object {
public:
virtual const char *get_string() = 0;
- virtual int get_value(units *);
+ virtual bool get_value(units *);
virtual void increment();
virtual void decrement();
virtual void set_increment(units);
@@ -52,7 +52,7 @@ public:
void add_value(units);
void set_value(units) = 0;
- int get_value(units *) = 0;
+ bool get_value(units *) = 0;
};
class variable_reg : public general_reg {
@@ -60,7 +60,7 @@ class variable_reg : public general_reg {
public:
variable_reg(int *);
void set_value(units);
- int get_value(units *);
+ bool get_value(units *);
};
extern object_dictionary number_reg_dictionary;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 05/08: [troff]: Refactor `get_value` member functions.,
G. Branden Robinson <=