Use -include only when using pch.

Document OptionalValue.
Use spaces when formatting date/time.
Capitalize some property names for consistency.
This commit is contained in:
Alexander Shaduri
2011-03-09 11:26:52 +00:00
parent 449b645278
commit 6c404d57c9
6 changed files with 66 additions and 43 deletions
+8 -8
View File
@@ -433,7 +433,8 @@ _AM_SUBST_NOTMAKE([RES_TARGETS])
ADDITIONAL_FLAGS="-DPACKAGE_PKGDATA_DIR=\"\\\"\$(pkgdatadir)\\\"\" \
-DPACKAGE_SYSCONF_DIR=\"\\\"\$(sysconfdir)\\\"\" \
-DTOP_SRC_DIR=\"\\\"\$(top_srcdir)\\\"\""
-DTOP_SRC_DIR=\"\\\"\$(top_srcdir)\\\"\" \
-DHZ_USE_GLOBAL_MACROS=1"
#CFLAGS="$CFLAGS $ADDITIONAL_FLAGS"
CXXFLAGS="$CXXFLAGS $ADDITIONAL_FLAGS"
@@ -450,13 +451,12 @@ ADDITIONAL_INCLUDES="-I\$(top_builddir) -I\$(top_srcdir)/src -I\$(top_srcdir)/sr
# with pgi and older sunstudio (the one in solaris10, for example).
# Note: some gcc-frontend-based compilers may have to be added here
# (e.g. gccfss (gcc frontend / sun backend), etc...).
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "intel" \
|| test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
# This auto-includes this file when compiling any file. Benefits include pch support.
ADDITIONAL_INCLUDES="$ADDITIONAL_INCLUDES -include global_macros.h"
else # sun, pgi, others...
# This forces the file to be included manually.
ADDITIONAL_INCLUDES="$ADDITIONAL_INCLUDES -DHZ_NO_COMPILER_AUTOINCLUDE"
# We use -include only when using pch.
if test "x$app_cv_compiler_gcc_pch" = "xyes"; then
if test "$ax_cv_cxx_compiler_vendor" = "gnu" || test "$ax_cv_cxx_compiler_vendor" = "intel" || test "$ax_cv_cxx_compiler_vendor" = "pathscale"; then
# This auto-includes this file when compiling any file. Benefits include pch support.
ADDITIONAL_INCLUDES="$ADDITIONAL_INCLUDES -include global_macros.h"
fi
fi
# our flags must be before all the others
+7 -7
View File
@@ -435,7 +435,7 @@ bool SmartctlParser::parse_section_info_property(StorageProperty& p)
p.value_integer = v;
} else if (app_pcre_match("/Device is/mi", p.reported_name)) {
p.set_name(p.reported_name, "in_smartctl_db", "Is in smartctl database");
p.set_name(p.reported_name, "in_smartctl_db", "In Smartctl Database");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = (!app_pcre_match("/Not in /mi", p.reported_value));
@@ -444,29 +444,29 @@ bool SmartctlParser::parse_section_info_property(StorageProperty& p)
// Don't put complete messages here - they change across smartctl versions.
if (app_pcre_match("/Available - device has/mi", p.reported_value)) {
p.set_name(p.reported_name, "smart_supported", "SMART supported");
p.set_name(p.reported_name, "smart_supported", "SMART Supported");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = true;
} else if (app_pcre_match("/Enabled/mi", p.reported_value)) {
p.set_name(p.reported_name, "smart_enabled", "SMART enabled");
p.set_name(p.reported_name, "smart_enabled", "SMART Enabled");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = true;
} else if (app_pcre_match("/Disabled/mi", p.reported_value)) {
p.set_name(p.reported_name, "smart_enabled", "SMART enabled");
p.set_name(p.reported_name, "smart_enabled", "SMART Enabled");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = false;
} else if (app_pcre_match("/Unavailable/mi", p.reported_value)) {
p.set_name(p.reported_name, "smart_supported", "SMART supported");
p.set_name(p.reported_name, "smart_supported", "SMART Supported");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = false;
// this should be last - when ambiguous state is detected, usually smartctl
// retries with other methods and prints one of the above.
} else if (app_pcre_match("/Ambiguous/mi", p.reported_value)) {
p.set_name(p.reported_name, "smart_supported", "SMART supported");
p.set_name(p.reported_name, "smart_supported", "SMART Supported");
p.value_type = StorageProperty::value_type_bool;
p.value_bool = true; // let's be optimistic - just hope that it doesn't hurt.
@@ -578,7 +578,7 @@ bool SmartctlParser::parse_section_data_subsection_health(const std::string& sub
// only one attribute in this section
if (app_pcre_match("/SMART overall-health self-assessment/mi", name)) {
pt.set_name(name, "overall_health", "Overall health self-assessment test");
pt.set_name(name, "overall_health", "Overall Health Self-Assessment Test");
pt.reported_value = value;
pt.value_type = StorageProperty::value_type_string;
pt.value_string = pt.reported_value;
+4 -3
View File
@@ -11,8 +11,9 @@
This file serves as a compile-time configuration for various
library components.
This file is not included directly, but through the compiler option
-include global_macros.h
This file is included from hz_config.h.
Additionally, it may be included through compiler's "-include" option
(if supported) for pch support.
*/
@@ -22,7 +23,7 @@ This file is not included directly, but through the compiler option
#endif
// So that others may check if "-include" works
// So that others may check whether this file was included or not.
#define APP_GLOBAL_MACROS_INCLUDED
+8 -6
View File
@@ -143,10 +143,11 @@ inline std::string format_time_length(int64_t secs)
if (hours > 0 && sec_diff < (-hour_size / 2))
days--;
return hz::number_to_string(days) + HZ_C_("time", "d") + " " + hz::number_to_string(hours) + HZ_C_("time", "h");
return hz::number_to_string(days) + " " + HZ_C_("time", "d")
+ " " + hz::number_to_string(hours) + " " + HZ_C_("time", "h");
} else { // display days only
return hz::number_to_string(days) + HZ_C_("time", "d");
return hz::number_to_string(days) + " " + HZ_C_("time", "d");
}
@@ -160,21 +161,22 @@ inline std::string format_time_length(int64_t secs)
if (minutes > 0 && sec_diff < (-min_size / 2))
hours--;
return hz::number_to_string(hours) + HZ_C_("time", "h") + " " + hz::number_to_string(minutes) + HZ_C_("time", "min");
return hz::number_to_string(hours) + " " + HZ_C_("time", "h")
+ " " + hz::number_to_string(minutes) + " " + HZ_C_("time", "min");
} else { // display hours only
return hz::number_to_string(hours) + HZ_C_("time", "h");
return hz::number_to_string(hours) + " " + HZ_C_("time", "h");
}
} else if (secs >= 100) {
int64_t minutes = (secs + min_size / 2) / min_size; // time in minutes (rounded to nearest)
return hz::number_to_string(minutes) + HZ_C_("time", "min");
return hz::number_to_string(minutes) + " " + HZ_C_("time", "min");
}
return hz::number_to_string(secs) + HZ_C_("time", "sec");
return hz::number_to_string(secs) + " " + HZ_C_("time", "sec");
}
+9 -11
View File
@@ -19,11 +19,10 @@
You should include this file if you're using any of:
- macros from autoconf-generated config.h
- macros from global_macros.h
This file has effect only if "-include" compiler option doesn't work.
The purpose of this file is to provide some common compatibility
solutions for the whole hz, while not depending on "-include"
compiler switches or pasting autoconf's config.h code in all files.
solutions for the whole hz, while not depending on pasting autoconf's
config.h code into all files.
*/
@@ -39,16 +38,15 @@ HZ library internal implementation helpers.
*/
// Define HZ_NO_COMPILER_AUTOINCLUDE=1 from a compiler option to enable
// Define HZ_USE_GLOBAL_MACROS=1 from a compiler option to enable
// auto-inclusion of global_macros.h.
#ifndef APP_GLOBAL_MACROS_INCLUDED // defined in global_macros.h
#if defined HZ_NO_COMPILER_AUTOINCLUDE && HZ_NO_COMPILER_AUTOINCLUDE
// define manually
#include "global_macros.h"
#else
#define HZ_NO_GLOBAL_MACROS 1
#endif
#if defined HZ_USE_GLOBAL_MACROS && HZ_USE_GLOBAL_MACROS
// define manually
#include "global_macros.h"
#define HZ_NO_GLOBAL_MACROS 0
#else
#define HZ_NO_GLOBAL_MACROS 1
#endif
+30 -8
View File
@@ -3,6 +3,11 @@
(C) 2008 - 2011 Alexander Shaduri <ashaduri 'at' gmail.com>
License: See LICENSE_zlib.txt file
***************************************************************************/
/// \file
/// \author Alexander Shaduri
/// \ingroup hz
/// \weakgroup hz
/// @{
#ifndef HZ_OPTIONAL_VALUE_H
#define HZ_OPTIONAL_VALUE_H
@@ -12,29 +17,30 @@
#include <ostream> // std::ostream, operator<<(ostream, const char*). iosfwd is not enough.
// A simple wrapper for type T, providing additional
// state - defined / undefined.
namespace hz {
/// A simple wrapper around type T, providing additional state - defined / undefined.
template<class T>
class OptionalValue {
public:
/// Wrapped type
typedef T value_type;
/// Constructor. Initial value is default-constructed, and the state is undefined.
OptionalValue() : value_(), defined_(false)
{ }
/// Construct from value \c v, setting the state to defined.
OptionalValue(const T& v) : value_(v), defined_(true)
{ }
/// Assignment operator
OptionalValue operator= (const OptionalValue<T>& other)
{
value_ = other.value_;
@@ -42,6 +48,8 @@ class OptionalValue {
return *this;
}
/// Assignment operator
OptionalValue operator= (OptionalValue<T>& other)
{
value_ = other.value_;
@@ -49,6 +57,9 @@ class OptionalValue {
return *this;
}
/// Assignment operator.
/// \post state is defined.
OptionalValue operator= (const T& v)
{
value_ = v;
@@ -56,6 +67,9 @@ class OptionalValue {
return *this;
}
/// Assignment operator.
/// \post state is defined.
OptionalValue operator= (T& v)
{
value_ = v;
@@ -64,18 +78,21 @@ class OptionalValue {
}
/// Comparison operator
bool operator== (const OptionalValue<T>& v)
{
return (defined_ == v.defined_ && value_ == v.value_);
}
/// Comparison operator
bool operator== (const T& v)
{
return (defined_ && value_ == v);
}
/// Set the state to undefined, set internal value to a default-constructed one.
void reset()
{
defined_ = false;
@@ -83,11 +100,14 @@ class OptionalValue {
}
/// Get the stored value. You may use this function only if defined() returns true.
const T& value() const
{
return value_;
}
/// Check the defined state.
bool defined() const
{
return defined_;
@@ -96,15 +116,15 @@ class OptionalValue {
private:
T value_;
bool defined_;
T value_; ///< Wrapped value
bool defined_; ///< "Defined" state
};
template<class T> inline
/// Stream output operator
template<class T>
std::ostream& operator<< (std::ostream& os, const OptionalValue<T>& v)
{
if (v.defined()) {
@@ -126,3 +146,5 @@ std::ostream& operator<< (std::ostream& os, const OptionalValue<T>& v)
#endif
/// @}