scalar.hpp

Go to the documentation of this file.
00001 /****
00002 ***** Copyright 2010 Intel Corporation All Rights Reserved.
00003 *****
00004 ***** The source code, information and material contained herein are owned by Intel Corporation or its suppliers  *****
00005 ***** or licensors, and title to such Material remains with Intel Corporation or its suppliers or licensors.      *****
00006 ***** The Material contains proprietary information of Intel or its suppliers and licensors. The Material is      *****
00007 ***** protected by worldwide copyright laws and treaty provisions. No part of the Material may be used, copied,   *****
00008 ***** reproduced, modified, published, uploaded, posted, transmitted, distributed or disclosed in any way without *****
00009 ***** Intel's prior express written permission.
00010 *****
00011 ***** No license under any patent, copyright or other intellectual property rights in the material is granted to  *****
00012 ***** or conferred upon you, either expressly, by implication, inducement, estoppel or otherwise. Any license     *****
00013 ***** under such intellectual property rights must be express and approved by Intel in writing.
00014 ****/
00015 
00016 /**** Copyright Ends ****/
00017 
00018 #ifndef ARBB_CPP_SCALAR_HPP
00019 #define ARBB_CPP_SCALAR_HPP
00020 
00021 #include "detail/scalar.hpp"
00022 #include "detail/select_if.hpp"
00023 #include "detail/context.hpp"
00024 #include "type_traits.hpp"
00025 #include "config.hpp"
00026 
00027 namespace ARBB_CPP_NS {
00028 
00031 
00044 template <arbb_scalar_type_t scalar_type>
00045 class scalar {
00046 public:
00047 
00050   scalar();
00051 
00054   scalar(const scalar& other);
00055 
00057   scalar(const typename uncaptured<scalar>::type& data);
00058 
00066   template<arbb_scalar_type_t other_scalar_type>
00067   scalar(const scalar<other_scalar_type>& other);
00068 
00071   scalar& operator=(const scalar& other);
00072 
00074   scalar& operator=(const typename uncaptured<scalar>::type& data);
00075 
00084   template<arbb_scalar_type_t other_scalar_type>
00085   scalar& operator=(const scalar<other_scalar_type>& other);
00086 
00088 
00090   const detail::scalar& detail_object() const;
00091 
00092   // Get the address of the debug data pointer
00093   void* get_debug_data_ptr() { return m_detail_scalar.get_debug_data_ptr(); }
00094 
00096   arbb_variable_t vm_variable() const;
00097 
00099 
00100 private:
00101   detail::scalar m_detail_scalar;
00102 }; // class scalar
00103 
00109 template <arbb_scalar_type_t scalar_type>
00110 typename uncaptured<scalar<scalar_type> >::type value(const scalar<scalar_type>& variable);
00111 
00113 typedef scalar<arbb_f32> f32;
00115 typedef scalar<arbb_f64> f64;
00117 typedef scalar<arbb_i8> i8;
00119 typedef scalar<arbb_i16> i16;
00121 typedef scalar<arbb_i32> i32;
00123 typedef scalar<arbb_i64> i64;
00125 typedef scalar<arbb_u8> u8;
00127 typedef scalar<arbb_u16> u16;
00129 typedef scalar<arbb_u32> u32;
00131 typedef scalar<arbb_u64> u64;
00133 typedef scalar<arbb_boolean> boolean;
00135 typedef scalar<arbb_isize> isize;
00137 typedef scalar<arbb_usize> usize;
00138 
00144 
00146 template<> struct captured<f32> { typedef f32 type; };
00148 template<> struct captured<f64> { typedef f64 type; };
00150 template<> struct captured<i8> { typedef i8 type; };
00152 template<> struct captured<i16> { typedef i16 type; };
00154 template<> struct captured<i32> { typedef i32 type; };
00156 template<> struct captured<i64> { typedef i64 type; };
00158 template<> struct captured<u8> { typedef u8 type; };
00160 template<> struct captured<u16> { typedef u16 type; };
00162 template<> struct captured<u32> { typedef u32 type; };
00164 template<> struct captured<u64> { typedef u64 type; };
00166 template<> struct captured<boolean> { typedef boolean type; };
00168 template<> struct captured<isize> { typedef isize type; };
00170 template<> struct captured<usize> { typedef usize type; };
00171 
00173 template<> struct captured<float> { typedef f32 type; };
00175 template<> struct captured<double> { typedef f64 type; };
00177 template<> struct captured<char> { typedef detail::select_if<-1 == static_cast<char>(-1), i8, u8>::type type; };
00179 template<> struct captured<signed char> { typedef i8 type; };
00181 template<> struct captured<signed short> { typedef i16 type; };
00183 template<> struct captured<signed int> { typedef i32 type; };
00185 template<> struct captured<signed long long> { typedef i64 type; };
00187 template<> struct captured<unsigned char> { typedef u8 type; };
00189 template<> struct captured<unsigned short> { typedef u16 type; };
00191 template<> struct captured<unsigned int> { typedef u32 type; };
00193 template<> struct captured<unsigned long long> { typedef u64 type; };
00195 template<> struct captured<bool> { typedef boolean type; };
00196 
00198 template<> struct uncaptured<f32> { typedef float type; };
00200 template<> struct uncaptured<f64> { typedef double type; };
00202 template<> struct uncaptured<i8> { typedef signed char type; };
00204 template<> struct uncaptured<i16> { typedef signed short type; };
00206 template<> struct uncaptured<i32> { typedef signed int type; };
00208 template<> struct uncaptured<i64> { typedef signed long long type; };
00210 template<> struct uncaptured<u8> { typedef unsigned char type; };
00212 template<> struct uncaptured<u16> { typedef unsigned short type; };
00214 template<> struct uncaptured<u32> { typedef unsigned int type; };
00216 template<> struct uncaptured<u64> { typedef unsigned long long type; };
00218 template<> struct uncaptured<boolean> { typedef bool type; };
00219 #ifdef ARBB_CPP_DOXYGEN_ONLY
00220 
00221 template<> struct uncaptured<isize> { typedef platform_specific type; };
00223 template<> struct uncaptured<usize> { typedef platform_specific type; };
00224 #else
00225 #  if ARBB_IS_32BIT_ENV
00226 template<> struct uncaptured<isize> { typedef uncaptured<i32>::type type; };
00227 template<> struct uncaptured<usize> { typedef uncaptured<u32>::type type; };
00228 #  else
00229 template<> struct uncaptured<isize> { typedef uncaptured<i64>::type type; };
00230 template<> struct uncaptured<usize> { typedef uncaptured<u64>::type type; };
00231 #  endif
00232 #endif
00233 
00235 template<> struct uncaptured<float> { typedef float type; };
00237 template<> struct uncaptured<double> { typedef double type; };
00239 template<> struct uncaptured<char> { typedef char type; };
00241 template<> struct uncaptured<signed char> { typedef signed char type; };
00243 template<> struct uncaptured<signed short> { typedef signed short type; };
00245 template<> struct uncaptured<signed int> { typedef signed int type; };
00247 template<> struct uncaptured<signed long long> { typedef signed long long type; };
00249 template<> struct uncaptured<unsigned char> { typedef unsigned char type; };
00251 template<> struct uncaptured<unsigned short> { typedef unsigned short type; };
00253 template<> struct uncaptured<unsigned int> { typedef unsigned int type; };
00255 template<> struct uncaptured<unsigned long long> { typedef unsigned long long type; };
00257 template<> struct uncaptured<bool> { typedef bool type; };
00258 
00262 template<arbb_scalar_type_t scalar_type> struct boolean_type<scalar<scalar_type> > { typedef boolean type; };
00263 
00265 template<arbb_scalar_type_t scalar_type> struct compare_type<scalar<scalar_type> > { typedef isize type; };
00266 
00268 
00270 
00271 // Implementation
00272 
00274 
00275 template <arbb_scalar_type_t scalar_type>
00276 scalar<scalar_type>::scalar()
00277 : m_detail_scalar(detail::scalar::create(scalar_type, std::string("")))
00278 {
00279   *this = scalar<scalar_type>(0);
00280 }
00281 
00282 template <arbb_scalar_type_t scalar_type>
00283 scalar<scalar_type>::scalar(const scalar<scalar_type>& other)
00284 : m_detail_scalar(detail::scalar::create(scalar_type, std::string("")))
00285 {
00286   m_detail_scalar.copy(other.detail_object());
00287 }
00288 
00289 template <arbb_scalar_type_t scalar_type>
00290 scalar<scalar_type>::scalar(const typename uncaptured<scalar>::type& data)
00291   : m_detail_scalar(detail::scalar::create(scalar_type, reinterpret_cast<const void*>(&data))) {
00292 }
00293 
00294 template <arbb_scalar_type_t scalar_type>
00295 template <arbb_scalar_type_t other_scalar_type>
00296 scalar<scalar_type>::scalar(const scalar<other_scalar_type>& other)
00297 : m_detail_scalar(detail::scalar::create(scalar_type, std::string("")))
00298 {
00299   *this = other;
00300 }
00301 
00302 template <arbb_scalar_type_t scalar_type>
00303 const detail::scalar& scalar<scalar_type>::detail_object() const
00304 {
00305   return m_detail_scalar;
00306 }
00307 
00308 template <arbb_scalar_type_t scalar_type>
00309 arbb_variable_t scalar<scalar_type>::vm_variable() const
00310 {
00311   return m_detail_scalar;
00312 }
00313 
00314 template <arbb_scalar_type_t scalar_type>
00315 scalar<scalar_type>& scalar<scalar_type>::operator=(const scalar<scalar_type>& other)
00316 {
00317   if (this != &other) {
00318     m_detail_scalar.copy(other.detail_object());
00319   }
00320 
00321   return *this;
00322 }
00323 
00324 template <arbb_scalar_type_t scalar_type>
00325 scalar<scalar_type>& scalar<scalar_type>::operator=(const typename uncaptured<scalar>::type& data)
00326 {
00327   detail::scalar new_scalar(detail::scalar::create(scalar_type, reinterpret_cast<const void*>(&data)));
00328   m_detail_scalar.copy(new_scalar);
00329   return *this;
00330 }
00331 
00332 template <arbb_scalar_type_t scalar_type>
00333 template <arbb_scalar_type_t other_scalar_type>
00334 scalar<scalar_type>& scalar<scalar_type>::operator=(const scalar<other_scalar_type>& other)
00335 {
00336   arbb_variable_t output = this->vm_variable();
00337   arbb_variable_t input = other.vm_variable();
00338 
00339   void* debug_data_ptrs[] = { get_debug_data_ptr() };
00340 
00341   arbb_op(detail::function::current(), arbb_op_cast, &output, &input, debug_data_ptrs, detail::throw_on_error_details());
00342 
00343   return *this;
00344 }
00345 
00346 template <arbb_scalar_type_t scalar_type>
00347 typename uncaptured<scalar<scalar_type> >::type value(const scalar<scalar_type>& var)
00348 {
00349   if (var.detail_object().local()) {
00350     throw exception(std::string("Extracting values from local variables is not allowed."));
00351   }
00352 
00353   typename uncaptured<scalar<scalar_type> >::type ret;
00354   arbb_read_scalar(detail::context(), var.detail_object().variable(), &ret, detail::throw_on_error_details());
00355   return ret;
00356 }
00357 
00359 
00360 } // namespace ARBB_CPP_NS
00361 
00362 #endif // ARBB_CPP_SCALAR_HPP

Submit feedback on this help topic

Copyright © 2010, Intel Corporation. All rights reserved.