From 98ad0ff1b0880892ee74a8c11752dc171f88b873 Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" Date: Tue, 10 Apr 2012 11:53:07 +0000 Subject: [PATCH] Move the COMPILE_ASSERT macro to its own header file. TEST=n/a BUG=none Review URL: https://webrtc-codereview.appspot.com/492002 git-svn-id: http://webrtc.googlecode.com/svn/trunk@2001 4adac7df-926f-26a2-2b94-8c16560cd09d --- .../source/rtp_format_vp8_unittest.cc | 12 +++------ .../interface/compile_assert.h | 27 +++++++++++++++++++ .../source/system_wrappers.gyp | 1 + 3 files changed, 31 insertions(+), 9 deletions(-) create mode 100644 src/system_wrappers/interface/compile_assert.h diff --git a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc index a6f9632850..5c95a72f1d 100644 --- a/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc +++ b/src/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source @@ -15,20 +15,14 @@ #include +#include "compile_assert.h" + #include "modules/rtp_rtcp/source/rtp_format_vp8.h" #include "modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h" #include "typedefs.h" namespace webrtc { -template -struct CompileAssert { -}; - -#undef COMPILE_ASSERT -#define COMPILE_ASSERT(expr, msg) \ - typedef CompileAssert<(bool(expr))> msg[bool(expr) ? 1 : -1] - class RtpFormatVp8Test : public ::testing::Test { protected: RtpFormatVp8Test() : helper_(NULL) {} diff --git a/src/system_wrappers/interface/compile_assert.h b/src/system_wrappers/interface/compile_assert.h new file mode 100644 index 0000000000..3ea8bbadfb --- /dev/null +++ b/src/system_wrappers/interface/compile_assert.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. + * + * Use of this source code is governed by a BSD-style license + * that can be found in the LICENSE file in the root of the source + * tree. An additional intellectual property rights grant can be found + * in the file PATENTS. All contributing project authors may + * be found in the AUTHORS file in the root of the source tree. + */ + +#ifndef WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ +#define WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ + +template +struct CompileAssert {}; + +// Use this macro to verify at compile time that certain restrictions are met. +// The first argument is the expression to evaluate, the second is a unique +// identifier for the assert. +// Example: +// COMPILE_ASSERT(sizeof(foo) < 128, foo_too_large); +#undef COMPILE_ASSERT +#define COMPILE_ASSERT(expr, msg) \ + typedef CompileAssert(expr)> \ + msg[static_cast(expr) ? 1 : -1] + +#endif // WEBRTC_SYSTEM_WRAPPERS_INTERFACE_COMPILE_ASSERT_H_ diff --git a/src/system_wrappers/source/system_wrappers.gyp b/src/system_wrappers/source/system_wrappers.gyp index 79820e93f6..1d066b49d7 100644 --- a/src/system_wrappers/source/system_wrappers.gyp +++ b/src/system_wrappers/source/system_wrappers.gyp @@ -24,6 +24,7 @@ 'sources': [ '../interface/aligned_malloc.h', '../interface/atomic32_wrapper.h', + '../interface/compile_assert.h', '../interface/condition_variable_wrapper.h', '../interface/cpu_info.h', '../interface/cpu_wrapper.h',