From 8dfbf6c19e0187e7cc5010e617cf4f4b3e227867 Mon Sep 17 00:00:00 2001 From: Murray Cumming Date: Fri, 31 Jul 2015 11:54:29 +0200 Subject: C++11: Use auto. --- cairomm/context.cc | 48 +++++++++++------------ cairomm/device.cc | 4 +- cairomm/fontface.cc | 26 ++++++------- cairomm/fontface.h | 2 +- cairomm/fontoptions.cc | 10 ++--- cairomm/matrix.cc | 2 +- cairomm/pattern.cc | 8 ++-- cairomm/quartz_surface.cc | 4 +- cairomm/region.cc | 18 ++++----- cairomm/scaledfont.cc | 8 ++-- cairomm/script.cc | 12 +++--- cairomm/script_surface.cc | 4 +- cairomm/surface.cc | 78 +++++++++++++++++++------------------- cairomm/win32_font.cc | 4 +- cairomm/win32_surface.cc | 8 ++-- cairomm/xlib_surface.cc | 26 ++++++------- examples/surfaces/image-surface.cc | 4 +- examples/surfaces/pdf-surface.cc | 4 +- examples/surfaces/ps-surface.cc | 4 +- examples/surfaces/svg-surface.cc | 4 +- examples/text/text-rotate.cc | 4 +- examples/text/toy-text.cc | 6 +-- examples/text/user-font.cc | 8 ++-- tests/test-context.cc | 40 +++++++++---------- tests/test-font-face.cc | 12 +++--- tests/test-font-options.cc | 8 ++-- tests/test-matrix.cc | 10 ++--- tests/test-scaled-font.cc | 28 +++++++------- tests/test-surface.cc | 18 ++++----- tests/test-user-font.cc | 12 +++--- 30 files changed, 212 insertions(+), 212 deletions(-) diff --git a/cairomm/context.cc b/cairomm/context.cc index bf70ef4..6d586ee 100644 --- a/cairomm/context.cc +++ b/cairomm/context.cc @@ -578,7 +578,7 @@ void Context::set_scaled_font(const RefPtr& scaled_font) RefPtr Context::get_scaled_font() { - cairo_scaled_font_t* font = cairo_get_scaled_font(cobj()); + auto font = cairo_get_scaled_font(cobj()); check_object_status_and_throw_exception(*this); return RefPtr(new ScaledFont(font, false /* does not have reference */)); } @@ -613,14 +613,14 @@ void Context::show_glyphs(const std::vector& glyphs) RefPtr Context::get_font_face() { - cairo_font_face_t* cfontface = cairo_get_font_face(cobj()); + auto cfontface = cairo_get_font_face(cobj()); check_object_status_and_throw_exception(*this); return RefPtr(new FontFace(cfontface, false /* does not have reference */)); } RefPtr Context::get_font_face() const { - cairo_font_face_t* cfontface = cairo_get_font_face(const_cast(cobj())); + auto cfontface = cairo_get_font_face(const_cast(cobj())); check_object_status_and_throw_exception(*this); return RefPtr(new FontFace(cfontface, false /* does not have reference */)); } @@ -667,7 +667,7 @@ void Context::glyph_path(const std::vector& glyphs) Operator Context::get_operator() const { - const Operator result = + const auto result = static_cast(cairo_get_operator(const_cast(cobj()))); check_object_status_and_throw_exception(*this); return result; @@ -675,7 +675,7 @@ Operator Context::get_operator() const static RefPtr get_pattern_wrapper (cairo_pattern_t* pattern) { - cairo_pattern_type_t pattern_type = cairo_pattern_get_type (pattern); + auto pattern_type = cairo_pattern_get_type (pattern); switch (pattern_type) { case CAIRO_PATTERN_TYPE_SOLID: @@ -697,28 +697,28 @@ static RefPtr get_pattern_wrapper (cairo_pattern_t* pattern) RefPtr Context::get_source() { - cairo_pattern_t* pattern = cairo_get_source(cobj()); + auto pattern = cairo_get_source(cobj()); check_object_status_and_throw_exception(*this); return get_pattern_wrapper (pattern); } RefPtr Context::get_source() const { - cairo_pattern_t* pattern = cairo_get_source(const_cast(cobj())); + auto pattern = cairo_get_source(const_cast(cobj())); check_object_status_and_throw_exception(*this); return RefPtr::cast_const (get_pattern_wrapper (pattern)); } double Context::get_tolerance() const { - const double result = cairo_get_tolerance(const_cast(cobj())); + const auto result = cairo_get_tolerance(const_cast(cobj())); check_object_status_and_throw_exception(*this); return result; } Antialias Context::get_antialias() const { - const Antialias result = static_cast(cairo_get_antialias(const_cast(cobj()))); + const auto result = static_cast(cairo_get_antialias(const_cast(cobj()))); check_object_status_and_throw_exception(*this); return result; } @@ -736,35 +736,35 @@ void Context::get_current_point(double& x, double& y) const FillRule Context::get_fill_rule() const { - const FillRule result = static_cast(cairo_get_fill_rule(const_cast(cobj()))); + const auto result = static_cast(cairo_get_fill_rule(const_cast(cobj()))); check_object_status_and_throw_exception(*this); return result; } double Context::get_line_width() const { - const double result = cairo_get_line_width(const_cast(cobj())); + const auto result = cairo_get_line_width(const_cast(cobj())); check_object_status_and_throw_exception(*this); return result; } LineCap Context::get_line_cap() const { - const LineCap result = static_cast(cairo_get_line_cap(const_cast(cobj()))); + const auto result = static_cast(cairo_get_line_cap(const_cast(cobj()))); check_object_status_and_throw_exception(*this); return result; } LineJoin Context::get_line_join() const { - const LineJoin result = static_cast(cairo_get_line_join(const_cast(cobj()))); + const auto result = static_cast(cairo_get_line_join(const_cast(cobj()))); check_object_status_and_throw_exception(*this); return result; } double Context::get_miter_limit() const { - const double result = cairo_get_miter_limit(const_cast(cobj())); + const auto result = cairo_get_miter_limit(const_cast(cobj())); check_object_status_and_throw_exception(*this); return result; } @@ -775,8 +775,8 @@ Context::get_dash(std::vector& dashes, double& offset) const // Allocate this array dynamically because some compilers complain about // allocating arrays on the stack when the array size isn't a compile-time // constant... - const int cnt = cairo_get_dash_count(const_cast(cobj())); - double* dash_array = new double[cnt]; + const auto cnt = cairo_get_dash_count(const_cast(cobj())); + auto dash_array = new double[cnt]; cairo_get_dash(const_cast(cobj()), dash_array, &offset); check_object_status_and_throw_exception(*this); dashes.assign(dash_array, dash_array + cnt); @@ -806,7 +806,7 @@ Matrix Context::get_matrix() const static RefPtr get_surface_wrapper (cairo_surface_t* surface) { - cairo_surface_type_t surface_type = cairo_surface_get_type (surface); + auto surface_type = cairo_surface_get_type (surface); switch (surface_type) { case CAIRO_SURFACE_TYPE_IMAGE: @@ -864,21 +864,21 @@ RefPtr get_surface_wrapper (cairo_surface_t* surface) RefPtr Context::get_target() { - cairo_surface_t* surface = cairo_get_target(const_cast(cobj())); + auto surface = cairo_get_target(const_cast(cobj())); check_object_status_and_throw_exception(*this); return get_surface_wrapper (surface); } RefPtr Context::get_target() const { - cairo_surface_t* surface = cairo_get_target(const_cast(cobj())); + auto surface = cairo_get_target(const_cast(cobj())); check_object_status_and_throw_exception(*this); return RefPtr::cast_const (get_surface_wrapper (surface)); } Path* Context::copy_path() const { - cairo_path_t* cresult = cairo_copy_path(const_cast(cobj())); + auto cresult = cairo_copy_path(const_cast(cobj())); check_object_status_and_throw_exception(*this); return new Path(cresult, true /* take ownership */); //The caller must delete it. } @@ -892,7 +892,7 @@ void Context::get_path_extents(double& x1, double& y1, double& x2, double& y2) c Path* Context::copy_path_flat() const { - cairo_path_t* cresult = cairo_copy_path_flat(const_cast(cobj())); + auto cresult = cairo_copy_path_flat(const_cast(cobj())); check_object_status_and_throw_exception(*this); return new Path(cresult, true /* take ownership */); //The caller must delete it. } @@ -917,7 +917,7 @@ void Context::push_group_with_content(Content content) RefPtr Context::pop_group() { - cairo_pattern_t* pattern = cairo_pop_group(cobj()); + auto pattern = cairo_pop_group(cobj()); check_object_status_and_throw_exception(*this); return get_pattern_wrapper(pattern); } @@ -930,7 +930,7 @@ void Context::pop_group_to_source() RefPtr Context::get_group_target() { - cairo_surface_t* surface = cairo_get_group_target(cobj()); + auto surface = cairo_get_group_target(cobj()); // surface can be NULL if you're not between push/pop group calls if(!surface) { @@ -943,7 +943,7 @@ RefPtr Context::get_group_target() RefPtr Context::get_group_target() const { - cairo_surface_t* surface = cairo_get_group_target(const_cast(cobj())); + auto surface = cairo_get_group_target(const_cast(cobj())); // surface can be NULL if you're not between push/pop group calls if(!surface) { diff --git a/cairomm/device.cc b/cairomm/device.cc index b53f252..9383064 100644 --- a/cairomm/device.cc +++ b/cairomm/device.cc @@ -49,7 +49,7 @@ void Device::unreference() const DeviceType Device::get_type() const { - cairo_device_type_t surface_type = + auto surface_type = cairo_device_get_type(const_cast(cobj())); check_object_status_and_throw_exception(*this); return static_cast(surface_type); @@ -69,7 +69,7 @@ void Device::finish() void Device::acquire() { - ErrorStatus status = cairo_device_acquire(m_cobject); + auto status = cairo_device_acquire(m_cobject); check_status_and_throw_exception(status); } diff --git a/cairomm/fontface.cc b/cairomm/fontface.cc index cb1468f..c44363e 100644 --- a/cairomm/fontface.cc +++ b/cairomm/fontface.cc @@ -60,21 +60,21 @@ void FontFace::unreference() const /* void* FontFace::get_user_data(const cairo_user_data_key_t *key) { - void* result = cairo_font_face_get_user_data(m_cobject, key); + auto result = cairo_font_face_get_user_data(m_cobject, key); check_object_status_and_throw_exception(*this); return result; } void FontFace::set_user_data(const cairo_user_data_key_t* key, void *user_data, cairo_destroy_func_t destroy) { - const ErrorStatus status = (ErrorStatus)cairo_font_face_set_user_data(m_cobject, key, user_data, destroy); + const auto status = (ErrorStatus)cairo_font_face_set_user_data(m_cobject, key, user_data, destroy); check_status_and_throw_exception(status); } */ FontType FontFace::get_type() const { - cairo_font_type_t font_type = cairo_font_face_get_type(m_cobject); + auto font_type = cairo_font_face_get_type(m_cobject); check_object_status_and_throw_exception(*this); return static_cast(font_type); } @@ -132,9 +132,9 @@ UserFontFace::init_cb(cairo_scaled_font_t* scaled_font, cairo_t *cr, cairo_font_extents_t* metrics) { - cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + auto face = cairo_scaled_font_get_font_face(scaled_font); // we've stored a pointer to the wrapper object in the C object's user_data - UserFontFace* instance = + auto instance = static_cast(cairo_font_face_get_user_data(face, &user_font_key)); @@ -180,9 +180,9 @@ UserFontFace::unicode_to_glyph_cb(cairo_scaled_font_t *scaled_font, unsigned long unicode, unsigned long *glyph) { - cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + auto face = cairo_scaled_font_get_font_face(scaled_font); // we've stored a pointer to the wrapper object in the C object's user_data - UserFontFace* instance = + auto instance = static_cast(cairo_font_face_get_user_data(face, &user_font_key)); if(instance) @@ -226,9 +226,9 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, int *num_clusters, cairo_text_cluster_flags_t *cluster_flags) { - cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + auto face = cairo_scaled_font_get_font_face(scaled_font); // we've stored a pointer to the wrapper object in the C object's user_data - UserFontFace* instance = + auto instance = static_cast(cairo_font_face_get_user_data(face, &user_font_key)); @@ -239,9 +239,9 @@ UserFontFace::text_to_glyphs_cb(cairo_scaled_font_t *scaled_font, std::vector glyph_v; std::vector cluster_v; const std::string utf8_str(utf8, utf8 + utf8_len); - TextClusterFlags local_flags = static_cast(0); + auto local_flags = static_cast(0); - ErrorStatus status = + auto status = instance->text_to_glyphs(RefPtr(new ScaledFont(scaled_font)), utf8_str, glyph_v, cluster_v, local_flags); @@ -326,9 +326,9 @@ UserFontFace::render_glyph_cb(cairo_scaled_font_t *scaled_font, cairo_t *cr, cairo_text_extents_t *metrics) { - cairo_font_face_t* face = cairo_scaled_font_get_font_face(scaled_font); + auto face = cairo_scaled_font_get_font_face(scaled_font); // we've stored a pointer to the wrapper object in the C object's user_data - UserFontFace* instance = + auto instance = static_cast(cairo_font_face_get_user_data(face, &user_font_key)); if(instance) diff --git a/cairomm/fontface.h b/cairomm/fontface.h index 25268ca..aa0e0cc 100644 --- a/cairomm/fontface.h +++ b/cairomm/fontface.h @@ -190,7 +190,7 @@ protected: * * @code * { - * Cairo::RefPtr face = MyUserFont::create(); + * auto face = MyUserFont::create(); * cr->set_font_face(face); * } // scope for demonstration purposes * diff --git a/cairomm/fontoptions.cc b/cairomm/fontoptions.cc index 2ba339d..932dfbe 100644 --- a/cairomm/fontoptions.cc +++ b/cairomm/fontoptions.cc @@ -96,7 +96,7 @@ void FontOptions::merge(const FontOptions& src) unsigned long FontOptions::hash() const { - const unsigned long result = cairo_font_options_hash(m_cobject); + const auto result = cairo_font_options_hash(m_cobject); check_object_status_and_throw_exception(*this); return result; } @@ -109,7 +109,7 @@ void FontOptions::set_antialias(Antialias antialias) Antialias FontOptions::get_antialias() const { - const Antialias result = static_cast(cairo_font_options_get_antialias(m_cobject)); + const auto result = static_cast(cairo_font_options_get_antialias(m_cobject)); check_object_status_and_throw_exception(*this); return result; } @@ -122,7 +122,7 @@ void FontOptions::set_subpixel_order(SubpixelOrder subpixel_order) SubpixelOrder FontOptions::get_subpixel_order() const { - const SubpixelOrder result = static_cast(cairo_font_options_get_subpixel_order(m_cobject)); + const auto result = static_cast(cairo_font_options_get_subpixel_order(m_cobject)); check_object_status_and_throw_exception(*this); return result; } @@ -135,7 +135,7 @@ void FontOptions::set_hint_style(HintStyle hint_style) HintStyle FontOptions::get_hint_style() const { - const HintStyle result = static_cast(cairo_font_options_get_hint_style(m_cobject)); + const auto result = static_cast(cairo_font_options_get_hint_style(m_cobject)); check_object_status_and_throw_exception(*this); return result; } @@ -149,7 +149,7 @@ void FontOptions::set_hint_metrics(HintMetrics hint_metrics) HintMetrics FontOptions::get_hint_metrics() const { - const HintMetrics result = + const auto result = static_cast(cairo_font_options_get_hint_metrics(m_cobject)); check_object_status_and_throw_exception(*this); return result; diff --git a/cairomm/matrix.cc b/cairomm/matrix.cc index aa74882..4a48f2c 100644 --- a/cairomm/matrix.cc +++ b/cairomm/matrix.cc @@ -75,7 +75,7 @@ void Matrix::rotate(double radians) void Matrix::invert() { - cairo_status_t status = cairo_matrix_invert(this); + auto status = cairo_matrix_invert(this); check_status_and_throw_exception(status); } diff --git a/cairomm/pattern.cc b/cairomm/pattern.cc index a57798a..aa2bae1 100644 --- a/cairomm/pattern.cc +++ b/cairomm/pattern.cc @@ -87,7 +87,7 @@ Matrix Pattern::get_matrix() const PatternType Pattern::get_type() const { - cairo_pattern_type_t pattern_type = cairo_pattern_get_type(m_cobject); + auto pattern_type = cairo_pattern_get_type(m_cobject); check_object_status_and_throw_exception(*this); return static_cast(pattern_type); } @@ -100,7 +100,7 @@ void Pattern::set_extend(Extend extend) Extend Pattern::get_extend() const { - const Extend result = static_cast(cairo_pattern_get_extend(m_cobject)); + const auto result = static_cast(cairo_pattern_get_extend(m_cobject)); check_object_status_and_throw_exception(*this); return result; } @@ -124,7 +124,7 @@ SolidPattern::~SolidPattern() RefPtr SolidPattern::create_rgb(double red, double green, double blue) { - cairo_pattern_t* cobject = cairo_pattern_create_rgb(red, green, blue); + auto cobject = cairo_pattern_create_rgb(red, green, blue); check_status_and_throw_exception(cairo_pattern_status(cobject)); return RefPtr(new SolidPattern(cobject, true /* has reference */)); } @@ -191,7 +191,7 @@ void SurfacePattern::set_filter(Filter filter) Filter SurfacePattern::get_filter() const { - Filter result = static_cast(cairo_pattern_get_filter(m_cobject)); + auto result = static_cast(cairo_pattern_get_filter(m_cobject)); check_object_status_and_throw_exception(*this); return result; } diff --git a/cairomm/quartz_surface.cc b/cairomm/quartz_surface.cc index b5000c6..006ef9f 100644 --- a/cairomm/quartz_surface.cc +++ b/cairomm/quartz_surface.cc @@ -40,7 +40,7 @@ CGContextRef QuartzSurface::get_cg_context() const RefPtr QuartzSurface::create(CGContextRef cg_context, int width, int height) { - cairo_surface_t* cobject = cairo_quartz_surface_create_for_cg_context(cg_context, + auto cobject = cairo_quartz_surface_create_for_cg_context(cg_context, width, height); check_status_and_throw_exception(cairo_surface_status(cobject)); return RefPtr(new QuartzSurface(cobject, true /* has reference */)); @@ -48,7 +48,7 @@ RefPtr QuartzSurface::create(CGContextRef cg_context, int width, RefPtr QuartzSurface::create(Format format, int width, int height) { - cairo_surface_t* cobject = cairo_quartz_surface_create((cairo_format_t)format, width, height); + auto cobject = cairo_quartz_surface_create((cairo_format_t)format, width, height); check_status_and_throw_exception(cairo_surface_status(cobject)); return RefPtr(new QuartzSurface(cobject, true /* has reference */)); } diff --git a/cairomm/region.cc b/cairomm/region.cc index 55b6154..945bf7b 100644 --- a/cairomm/region.cc +++ b/cairomm/region.cc @@ -39,7 +39,7 @@ Region::Region(const RectangleInt& rectangle) Region::Region(const std::vector& rects) : m_cobject(0) { - RectangleInt *carray = new RectangleInt[rects.size()]; + auto *carray = new RectangleInt[rects.size()]; std::copy(rects.begin(), rects.end(), carray); m_cobject = cairo_region_create_rectangles (carray, rects.size()); @@ -148,49 +148,49 @@ void Region::translate(int dx, int dy) void Region::subtract(const RefPtr& other) { - ErrorStatus status = cairo_region_subtract(m_cobject, (other ? other->cobj() : 0)); + auto status = cairo_region_subtract(m_cobject, (other ? other->cobj() : 0)); check_status_and_throw_exception (status); } void Region::subtract(const RectangleInt& rectangle) { - ErrorStatus status = cairo_region_subtract_rectangle(m_cobject, &rectangle); + auto status = cairo_region_subtract_rectangle(m_cobject, &rectangle); check_status_and_throw_exception (status); } void Region::intersect(const RefPtr& other) { - ErrorStatus status = cairo_region_intersect(m_cobject, (other ? other->cobj() : 0)); + auto status = cairo_region_intersect(m_cobject, (other ? other->cobj() : 0)); check_status_and_throw_exception (status); } void Region::intersect(const RectangleInt& rectangle) { - ErrorStatus status = cairo_region_intersect_rectangle(m_cobject, &rectangle); + auto status = cairo_region_intersect_rectangle(m_cobject, &rectangle); check_status_and_throw_exception (status); } void Region::do_union(const RefPtr& other) { - ErrorStatus status = cairo_region_union(m_cobject, (other ? other->cobj() : 0)); + auto status = cairo_region_union(m_cobject, (other ? other->cobj() : 0)); check_status_and_throw_exception (status); } void Region::do_union(const RectangleInt& rectangle) { - ErrorStatus status = cairo_region_union_rectangle(m_cobject, &rectangle); + auto status = cairo_region_union_rectangle(m_cobject, &rectangle); check_status_and_throw_exception (status); } void Region::do_xor(const RefPtr& other) { - ErrorStatus status = cairo_region_xor(m_cobject, (other ? other->cobj() : 0)); + auto status = cairo_region_xor(m_cobject, (other ? other->cobj() : 0)); check_status_and_throw_exception (status); } void Region::do_xor(const RectangleInt& rectangle) { - ErrorStatus status = cairo_region_xor_rectangle(m_cobject, &rectangle); + auto status = cairo_region_xor_rectangle(m_cobject, &rectangle); check_status_and_throw_exception (status); } diff --git a/cairomm/scaledfont.cc b/cairomm/scaledfont.cc index a562619..fe8cbd5 100644 --- a/cairomm/scaledfont.cc +++ b/cairomm/scaledfont.cc @@ -98,7 +98,7 @@ void ScaledFont::glyph_extents(const std::vector& glyphs, TextExtents& ex RefPtr ScaledFont::get_font_face() const { - cairo_font_face_t* face = cairo_scaled_font_get_font_face(m_cobject); + auto face = cairo_scaled_font_get_font_face(m_cobject); check_object_status_and_throw_exception(*this); return RefPtr(new FontFace(face, false /* returned face doesn't have a reference */)); } @@ -137,7 +137,7 @@ void ScaledFont::get_ctm(cairo_matrix_t& ctm) const FontType ScaledFont::get_type() const { - cairo_font_type_t font_type = cairo_scaled_font_get_type(m_cobject); + auto font_type = cairo_scaled_font_get_type(m_cobject); check_object_status_and_throw_exception(*this); return static_cast(font_type); } @@ -154,7 +154,7 @@ ScaledFont::text_to_glyphs (double x, int num_clusters = -1; cairo_glyph_t* c_glyphs = 0; cairo_text_cluster_t* c_clusters = 0; - cairo_status_t status = cairo_scaled_font_text_to_glyphs(cobj(), x, y, + auto status = cairo_scaled_font_text_to_glyphs(cobj(), x, y, utf8.c_str(), utf8.size(), &c_glyphs, @@ -200,7 +200,7 @@ FtScaledFont::create(const RefPtr& font_face, FT_Face FtScaledFont::lock_face() { - FT_Face face = cairo_ft_scaled_font_lock_face(cobj()); + auto face = cairo_ft_scaled_font_lock_face(cobj()); check_object_status_and_throw_exception(*this); return face; } diff --git a/cairomm/script.cc b/cairomm/script.cc index ac8b22e..c13c595 100644 --- a/cairomm/script.cc +++ b/cairomm/script.cc @@ -34,7 +34,7 @@ Script::~Script() void Script::add_from_recording_surface(const RefPtr& recording_surface) { - ErrorStatus status = cairo_script_from_recording_surface(m_cobject, + auto status = cairo_script_from_recording_surface(m_cobject, recording_surface->cobj()); check_status_and_throw_exception(status); } @@ -56,7 +56,7 @@ void Script::write_comment(const std::string& comment) RefPtr