Skip to content

Commit

Permalink
Merge pull request #168 from fktn-k/feature/164_use_default_member_in…
Browse files Browse the repository at this point in the history
…it_vals

#164 Use default initial values for class member variables
  • Loading branch information
fktn-k authored Oct 20, 2023
2 parents 3fb68d9 + 3d24ee8 commit e0e9b28
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 81 deletions.
11 changes: 5 additions & 6 deletions include/fkYAML/detail/input/deserializer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,12 @@ class basic_deserializer
}

private:
BasicNodeType* m_current_node = nullptr; /** The currently focused YAML node. */
std::vector<BasicNodeType*> m_node_stack = {}; /** The stack of YAML nodes. */
yaml_version_t m_yaml_version = yaml_version_t::VER_1_2; /** The YAML version specification type. */
uint32_t m_current_indent_width = 0; /** The current indentation width. */
bool m_needs_anchor_impl = false; /** A flag to determine the need for YAML anchor node implementation */
BasicNodeType* m_current_node {nullptr}; /** The currently focused YAML node. */
std::vector<BasicNodeType*> m_node_stack {}; /** The stack of YAML nodes. */
yaml_version_t m_yaml_version {yaml_version_t::VER_1_2}; /** The YAML version specification type. */
bool m_needs_anchor_impl {false}; /** A flag to determine the need for YAML anchor node implementation */
string_type m_anchor_name {}; /** The last YAML anchor name. */
std::unordered_map<std::string, BasicNodeType> m_anchor_table = {}; /** The table of YAML anchor nodes. */
std::unordered_map<std::string, BasicNodeType> m_anchor_table {}; /** The table of YAML anchor nodes. */
};

} // namespace detail
Expand Down
10 changes: 5 additions & 5 deletions include/fkYAML/detail/input/input_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ class iterator_input_adapter
}

private:
IterType m_current;
IterType m_begin;
IterType m_end;
IterType m_current {};
IterType m_begin {};
IterType m_end {};
};

/**
Expand Down Expand Up @@ -156,7 +156,7 @@ class file_input_adapter
}

private:
std::FILE* m_file;
std::FILE* m_file {nullptr};
};

/**
Expand Down Expand Up @@ -243,7 +243,7 @@ class stream_input_adapter
}

private:
std::istream* m_istream;
std::istream* m_istream {nullptr};
};

///////////////////////////////////
Expand Down
9 changes: 4 additions & 5 deletions include/fkYAML/detail/input/input_handler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ class input_handler
* @param input_adapter An input adapter object
*/
explicit input_handler(InputAdapterType&& input_adapter)
: m_input_adapter(std::move(input_adapter)),
m_cur_pos(0)
: m_input_adapter(std::move(input_adapter))
{
get_next();
m_cur_pos = 0;
Expand Down Expand Up @@ -183,11 +182,11 @@ class input_handler
static constexpr int_type end_of_input = char_traits_type::eof();

//!< An input adapter object.
InputAdapterType m_input_adapter;
InputAdapterType m_input_adapter {};
//!< Cached characters retrieved from an input adapter object.
std::vector<int_type> m_cache;
std::vector<int_type> m_cache {};
//!< The current position in an input buffer.
size_t m_cur_pos;
size_t m_cur_pos {0};
};

} // namespace detail
Expand Down
43 changes: 6 additions & 37 deletions include/fkYAML/detail/input/lexical_analyzer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,35 +68,14 @@ class lexical_analyzer
using float_number_type = typename BasicNodeType::float_number_type;
using string_type = typename BasicNodeType::string_type;

private:
/**
* @struct position
* @brief Information set of analyzed data counters.
*/
struct position
{
//!< The total read char counts from the input buffer.
size_t total_read_char_counts = 0;
//!< The total read line counts.
size_t total_read_line_counts = 0;
//!< The total read char counts in the current line.
size_t read_char_counts_in_line = 0;
//!< The total char counts in the previous line.
size_t prev_char_counts_in_line = 0;
};

public:
/**
* @brief Construct a new lexical_analyzer object.
*/
explicit lexical_analyzer(InputAdapterType&& input_adapter)
: m_input_handler(std::move(input_adapter)),
m_value_buffer(),
m_position_info()
: m_input_handler(std::move(input_adapter))
{
}

public:
/**
* @brief Get the next lexical token type by scanning the left of the input buffer.
*
Expand Down Expand Up @@ -800,7 +779,6 @@ class lexical_analyzer

const bool needs_last_double_quote = (m_input_handler.get_current() == '\"');
const bool needs_last_single_quote = (m_input_handler.get_current() == '\'');
size_t start_pos_backup = m_position_info.total_read_char_counts;
char_int_type current = (needs_last_double_quote || needs_last_single_quote) ? m_input_handler.get_next()
: m_input_handler.get_current();

Expand Down Expand Up @@ -890,13 +868,6 @@ class lexical_analyzer
continue;
}

if (next == '\r' || next == '\n')
{
size_t current_pos_backup = m_position_info.total_read_char_counts;
m_position_info.total_read_char_counts = start_pos_backup;
m_position_info.total_read_char_counts = current_pos_backup;
}

return lexical_token_t::STRING_VALUE;
}

Expand Down Expand Up @@ -1169,17 +1140,15 @@ class lexical_analyzer
//!< An input buffer adapter to be analyzed.
input_handler_type m_input_handler;
//!< A temporal buffer to store a string to be parsed to an actual datum.
input_string_type m_value_buffer;
//!< The information set for input buffer.
position m_position_info;
input_string_type m_value_buffer {};
//!< The last found token type.
lexical_token_t m_last_token_type;
lexical_token_t m_last_token_type {lexical_token_t::END_OF_BUFFER};
//!< A temporal bool holder.
boolean_type m_boolean_val;
boolean_type m_boolean_val {false};
//!< A temporal integer holder.
integer_type m_integer_val;
integer_type m_integer_val {0};
//!< A temporal floating point number holder.
float_number_type m_float_val;
float_number_type m_float_val {0.0};
};

} // namespace detail
Expand Down
4 changes: 2 additions & 2 deletions include/fkYAML/detail/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,9 +570,9 @@ class iterator

private:
/** A type of the internally-held iterator. */
iterator_t m_inner_iterator_type;
iterator_t m_inner_iterator_type {iterator_t::SEQUENCE};
/** A holder of actual iterators. */
mutable iterator_holder m_iterator_holder;
mutable iterator_holder m_iterator_holder {};
};

} // namespace detail
Expand Down
29 changes: 8 additions & 21 deletions include/fkYAML/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ class basic_node
/** A pointer to the value of sequence type. */
sequence_type* p_sequence;
/** A pointer to the value of mapping type. This pointer is also used when node type is null. */
mapping_type* p_mapping;
mapping_type* p_mapping {nullptr};
/** A value of boolean type. */
boolean_type boolean;
/** A value of integer type. */
Expand Down Expand Up @@ -283,13 +283,7 @@ class basic_node
/**
* @brief Construct a new basic_node object of null type.
*/
basic_node() noexcept
: m_node_type(node_t::NULL_OBJECT),
m_yaml_version_type(yaml_version_t::VER_1_2),
m_node_value(),
m_anchor_name(nullptr)
{
}
basic_node() = default;

/**
* @brief Construct a new basic_node object with a specified type.
Expand All @@ -299,9 +293,7 @@ class basic_node
*/
explicit basic_node(const node_t type)
: m_node_type(type),
m_yaml_version_type(yaml_version_t::VER_1_2),
m_node_value(type),
m_anchor_name(nullptr)
m_node_value(type)
{
}

Expand All @@ -312,8 +304,7 @@ class basic_node
*/
basic_node(const basic_node& rhs)
: m_node_type(rhs.m_node_type),
m_yaml_version_type(rhs.m_yaml_version_type),
m_anchor_name(nullptr)
m_yaml_version_type(rhs.m_yaml_version_type)
{
switch (m_node_type)
{
Expand Down Expand Up @@ -414,10 +405,6 @@ class basic_node
int> = 0>
explicit basic_node(CompatibleType&& val) noexcept(
noexcept(ConverterType<U>::to_node(std::declval<basic_node&>(), std::declval<CompatibleType>())))
: m_node_type(node_t::NULL_OBJECT),
m_yaml_version_type(yaml_version_t::VER_1_2),
m_node_value(),
m_anchor_name(nullptr)
{
ConverterType<U>::to_node(*this, std::forward<CompatibleType>(val));
}
Expand Down Expand Up @@ -1359,13 +1346,13 @@ class basic_node

private:
/** The current node value type. */
node_t m_node_type;
node_t m_node_type {node_t::NULL_OBJECT};
/** The YAML version specification. */
yaml_version_t m_yaml_version_type;
yaml_version_t m_yaml_version_type {yaml_version_t::VER_1_2};
/** The current node value. */
node_value m_node_value;
node_value m_node_value {};
/** The anchor name for this node. */
std::string* m_anchor_name;
std::string* m_anchor_name {nullptr};
};

template <
Expand Down
9 changes: 4 additions & 5 deletions include/fkYAML/ordered_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ class ordered_map : public std::vector<std::pair<const Key, Value>, Allocator>
* @brief Construct a new ordered_map object.
*/
ordered_map() noexcept(noexcept(Container()))
: Container(),
m_compare()
: Container()
{
}

Expand All @@ -76,8 +75,7 @@ class ordered_map : public std::vector<std::pair<const Key, Value>, Allocator>
* @param init An initializer list to construct the inner container object.
*/
ordered_map(std::initializer_list<value_type> init)
: Container {init},
m_compare()
: Container {init}
{
}

Expand Down Expand Up @@ -210,7 +208,8 @@ class ordered_map : public std::vector<std::pair<const Key, Value>, Allocator>
}

private:
key_compare m_compare; /** The object for comparing keys. */
/** The object for comparing keys. */
key_compare m_compare {};
};

FK_YAML_NAMESPACE_END
Expand Down

0 comments on commit e0e9b28

Please sign in to comment.