Skip to content

Commit

Permalink
Polished CHpater12
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin committed Aug 16, 2017
1 parent 9adc077 commit f2ee387
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
46 changes: 30 additions & 16 deletions Chapter12/01_graph/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,28 @@ typedef boost::adjacency_list<

#include <boost/utility/string_ref.hpp>
#include <iostream>
template <class GraphT>
void find_and_print(const GraphT& g, boost::string_ref name) {
typedef typename boost::graph_traits<graph_type>
::vertex_iterator vert_it_t;

inline void find_and_print(
const graph_type& graph, boost::string_ref name)
{
typedef typename boost::graph_traits<
graph_type
>::vertex_iterator vert_it_t;

vert_it_t it, end;
boost::tie(it, end) = boost::vertices(g);
boost::tie(it, end) = boost::vertices(graph);

typedef typename boost::graph_traits<
graph_type
>::vertex_descriptor desc_t;

typedef boost::graph_traits<graph_type>::vertex_descriptor desc_t;
for (; it != end; ++ it) {
desc_t desc = *it;
if (boost::get(boost::vertex_bundle, g)[desc] == name.data()) {
const desc_t desc = *it;
const vertex_t& vertex = boost::get(
boost::vertex_bundle, graph
)[desc];

if (vertex == name.data()) {
break;
}
}
Expand All @@ -39,17 +50,19 @@ int main() {
C++ -> STL -> Boost -> C++ guru <- C
*/

typedef boost::graph_traits<graph_type>
::vertex_descriptor descriptor_t;
descriptor_t cpp
typedef boost::graph_traits<
graph_type
>::vertex_descriptor descriptor_t;

descriptor_t cpp
= boost::add_vertex(vertex_t("C++"), graph);
descriptor_t stl
descriptor_t stl
= boost::add_vertex(vertex_t("STL"), graph);
descriptor_t boost
descriptor_t boost
= boost::add_vertex(vertex_t("Boost"), graph);
descriptor_t guru
descriptor_t guru
= boost::add_vertex(vertex_t("C++ guru"), graph);
descriptor_t ansic
descriptor_t ansic
= boost::add_vertex(vertex_t("C"), graph);

BOOST_STATIC_ASSERT((boost::is_same<descriptor_t, std::size_t>::value));
Expand All @@ -62,4 +75,5 @@ int main() {

find_and_print(graph, "Boost");
find_and_print(graph, "C++ guru");
}
} // end of main

3 changes: 3 additions & 0 deletions Chapter12/02_graph_vis/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ typedef boost::adjacency_list<
, vertex_t
> graph_type;

#include <iosfwd>

namespace detail {
template <class GraphT>
class vertex_writer {
Expand All @@ -32,6 +34,7 @@ namespace detail {
} // namespace detail

#include <boost/graph/graphviz.hpp>

std::ostream& operator<<(std::ostream& out, const graph_type& g) {
detail::vertex_writer<graph_type> vw(g);
boost::write_graphviz(out, g, vw);
Expand Down
4 changes: 3 additions & 1 deletion Chapter12/05_testing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ struct foo {
void throws() const; // throws(std::logic_error)
};



#define BOOST_TEST_MODULE test_module_name
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_CASE(test_no_1) {
foo f1 = {1}, f2 = {2};
BOOST_CHECK(f1.is_not_null());

BOOST_CHECK_NE(f1, f2);

BOOST_CHECK_THROW(f1.throws(), std::logic_error);
Expand Down
7 changes: 2 additions & 5 deletions Chapter12/07_gil/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,12 @@ for (unsigned int y = 0; y < source.height(); ++y) {
}; // negate

int main(int argc, char *argv[]) {
if (argc < 2) {
assert(false);
}
assert(argc == 2);

typedef boost::mpl::vector<
boost::gil::gray8_image_t,
boost::gil::gray16_image_t,
boost::gil::rgb8_image_t,
boost::gil::rgb16_image_t
boost::gil::rgb8_image_t
> img_types;

std::string file_name(argv[1]);
Expand Down

0 comments on commit f2ee387

Please sign in to comment.