Add arraysize macro from Chromium

This commit is contained in:
John Maguire 2014-04-29 14:11:52 +02:00
parent 0392420cd8
commit 41e9c15248
5 changed files with 54 additions and 13 deletions

3
debian/copyright vendored
View File

@ -45,7 +45,8 @@ Files: src/core/fht.*
Copyright: 2004, Melchior FRANZ <mfranz@kde.org>
License: GPL-2+
Files: src/core/scoped_nsobject.h
Files: ext/libclementine-common/core/arraysize.h
src/core/scoped_nsobject.h
src/core/scoped_cftyperef.h
src/core/scoped_nsautorelease_pool.*
Copyright: 2011, The Chromium Authors

View File

@ -18,14 +18,9 @@
// it is used by the Spotify blob which links against libspotify and is not GPL
// compatible.
#include <algorithm>
#include "mediapipeline.h"
#include "spotifyclient.h"
#include "spotifykey.h"
#include "spotifymessages.pb.h"
#include "spotify_utilities.h"
#include "core/logging.h"
#include <algorithm>
#include <QCoreApplication>
#include <QDir>
@ -33,6 +28,13 @@
#include <QTcpSocket>
#include <QTimer>
#include "core/arraysize.h"
#include "core/logging.h"
#include "mediapipeline.h"
#include "spotifykey.h"
#include "spotifymessages.pb.h"
#include "spotify_utilities.h"
const int SpotifyClient::kSpotifyImageIDSize = 20;
const int SpotifyClient::kWaveHeaderSize = 44;
@ -615,7 +617,7 @@ void SpotifyClient::ConvertTrack(sp_track* track, pb::spotify::Track* pb) {
// URI - Blugh
char uri[256];
sp_link* link = sp_link_create_from_track(track, 0);
sp_link_as_string(link, uri, sizeof(uri));
sp_link_as_string(link, uri, arraysize(uri));
sp_link_release(link);
pb->set_uri(uri);
@ -645,7 +647,7 @@ void SpotifyClient::ConvertAlbum(sp_album* album, pb::spotify::Track* pb) {
// URI - Blugh
char uri[256];
sp_link* link = sp_link_create_from_album(album);
sp_link_as_string(link, uri, sizeof(uri));
sp_link_as_string(link, uri, arraysize(uri));
sp_link_release(link);
pb->set_uri(uri);

View File

@ -0,0 +1,34 @@
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// From Chromium src/base/macros.h
#include <stddef.h> // For size_t.
// The arraysize(arr) macro returns the # of elements in an array arr.
// The expression is a compile-time constant, and therefore can be
// used in defining new arrays, for example. If you use arraysize on
// a pointer by mistake, you will get a compile-time error.
//
// One caveat is that arraysize() doesn't accept any array of an
// anonymous type or a type defined inside a function. In these rare
// cases, you have to use the unsafe ARRAYSIZE_UNSAFE() macro below. This is
// due to a limitation in C++'s template system. The limitation might
// eventually be removed, but it hasn't happened yet.
// This template function declaration is used in defining arraysize.
// Note that the function doesn't need an implementation, as we only
// use its type.
template <typename T, size_t N>
char (&ArraySizeHelper(T (&array)[N]))[N];
// That gcc wants both of these prototypes seems mysterious. VC, for
// its part, can't decide which to use (another mystery). Matching of
// template overloads: the final frontier.
#ifndef _MSC_VER
template <typename T, size_t N>
char (&ArraySizeHelper(const T (&array)[N]))[N];
#endif
#define arraysize(array) (sizeof(ArraySizeHelper(array)))

View File

@ -16,13 +16,15 @@
*/
#include "nyancatanalyzer.h"
#include "core/logging.h"
#include <cmath>
#include <QTimerEvent>
#include <QBrush>
#include "core/arraysize.h"
#include "core/logging.h"
const char* NyanCatAnalyzer::kName = "Nyanalyzer cat";
const float NyanCatAnalyzer::kPixelScale = 0.02f;
@ -36,7 +38,7 @@ NyanCatAnalyzer::NyanCatAnalyzer(QWidget* parent)
px_per_frame_(0),
x_offset_(0),
background_brush_(QColor(0x0f, 0x43, 0x73)) {
memset(history_, 0, sizeof(history_));
memset(history_, 0, arraysize(history_));
for (int i = 0; i < kRainbowBands; ++i) {
colors_[i] = QPen(QColor::fromHsv(i * 255 / kRainbowBands, 255, 255),

View File

@ -20,6 +20,8 @@
#include <QPainter>
#include <QPalette>
#include "core/arraysize.h"
const int MoodbarRenderer::kNumHues = 12;
ColorVector MoodbarRenderer::Colors(const QByteArray& data, MoodbarStyle style,
@ -60,7 +62,7 @@ ColorVector MoodbarRenderer::Colors(const QByteArray& data, MoodbarStyle style,
int hue_distribution[360];
int total = 0;
memset(hue_distribution, 0, sizeof(hue_distribution));
memset(hue_distribution, 0, arraysize(hue_distribution));
ColorVector colors;