29 #ifndef VALUE_ARRAY_ADAPTER_H 30 #define VALUE_ARRAY_ADAPTER_H 47 #define SW16(s) _byteswap_ushort(s) 48 #define SW32(s) _byteswap_ulong(s) 49 #define SW64(s) _byteswap_uint64(s) 51 #include <libkern/OSByteOrder.h> 52 #define SW16(s) __builtin_bswap16( (s) ) 53 #define SW32(s) __builtin_bswap32( (s) ) 54 #define SW64(s) __builtin_bswap64( (s) ) 57 #define SW16(s) bswap_16(s) 58 #define SW32(s) bswap_32(s) 59 #define SW64(s) bswap_64(s) 70 template<
typename TTargetType>
74 template<
typename TSourceType>
75 static TTargetType
Convert (TSourceType src)
77 return static_cast<TTargetType
>(src);
85 template<
typename TSourceType>
96 template<
size_t TValueSize>
100 static void Extract (
const void *src,
void *dst)
102 std::reverse_copy(reinterpret_cast<const uint8_t*>(src),
103 reinterpret_cast<const uint8_t*>(src) + TValueSize,
104 reinterpret_cast<uint8_t*>(dst));
111 static void Extract (
const void *src,
void *dst)
113 *
reinterpret_cast<uint64_t*
>(dst) =
SW64(*reinterpret_cast<const uint64_t*>(src));
120 static void Extract (
const void *src,
void *dst)
122 *
reinterpret_cast<uint32_t*
>(dst) =
SW32(*reinterpret_cast<const uint32_t*>(src));
129 static void Extract (
const void *src,
void *dst)
131 *
reinterpret_cast<uint16_t*
>(dst) =
SW16(*reinterpret_cast<const uint16_t*>(src));
138 static void Extract (
const void *src,
void *dst)
140 *
reinterpret_cast<uint8_t*
>(dst) = *reinterpret_cast<const uint8_t*>(src);
169 void ReadFromPort ();
198 struct ValueArrayInternals;
216 template<
typename TValueNodeType,
typename TOutputValueType,
typename TEffectiveValueType = TOutputValueType>
229 current_array_getter(NULL)
269 std::vector<TOutputValueType> values(current_num_values);
270 GetAllValues (values);
316 assert (current_array_getter != NULL);
317 (this->*current_array_getter) (values);
337 if (!base_value || !selector)
343 INodeMap *node_map = base_value->GetNode()->GetNodeMap();
344 if (node_map != selector->GetNode()->GetNodeMap())
351 CStringPtr candidates_node = node_map->GetNode(
"ValueArrayCandidates");
365 GENICAM_NAMESPACE::gcstring_vector tokens;
366 Tokenize(candidates_str, tokens,
",");
370 +
"[" + selector->GetNode()->GetName() +
"]";
371 return tokens.contains (wanted);
383 template<
typename TFieldType>
386 assert (current_reg_length!=0 && current_address_step != 0);
390 values.resize (current_num_values);
397 ExtractFieldValues_Swap<TFieldType> (current_num_values,
398 static_cast<size_t>(current_address_step),
399 current_array_shadow, &values[0]);
403 ExtractFieldValues_Noswap<TFieldType> (current_num_values,
404 static_cast<size_t>(current_address_step),
405 current_array_shadow, &values[0]);
408 template<
typename TFieldType>
411 assert (current_reg_length!=0 && current_address_step != 0);
415 values.resize (current_num_values);
422 ExtractFieldBits_Swap<TFieldType> (current_num_values,
423 static_cast<size_t>(current_address_step),
425 current_array_shadow, &values[0]);
429 ExtractFieldBits_Noswap<TFieldType> (current_num_values,
430 static_cast<size_t>(current_address_step),
432 current_array_shadow, &values[0]);
439 template<
typename TFieldType>
441 const uint8_t *src, TOutputValueType *dst)
443 for (
size_t i = 0; i < num_values; ++i)
445 const uint8_t *field_ptr = src + i * address_step;
447 TFieldType field_value = *
reinterpret_cast<const TFieldType*
>(field_ptr);
448 dst[i] =
static_cast<TOutputValueType
>(EffectiveValue (field_value));
451 template<
typename TFieldType>
453 const uint8_t *src, TOutputValueType *dst)
455 for (
size_t i = 0; i < num_values; ++i)
457 const uint8_t *field_ptr = src + i * address_step;
459 TFieldType field_value = ReadSwapped<TFieldType> (field_ptr);
460 dst[i] =
static_cast<TOutputValueType
>(EffectiveValue (field_value));
463 template<
typename TFieldType>
465 uint64_t mask,
size_t shift,
466 const uint8_t *src, TOutputValueType *dst)
468 for (
size_t i = 0; i < num_values; ++i)
470 const uint8_t *field_ptr = src + i * address_step;
472 TFieldType field_value = *
reinterpret_cast<const TFieldType*
>(field_ptr);
473 uint64_t field_bits = mask & (field_value >> shift);
474 dst[i] =
static_cast<TOutputValueType
>(EffectiveValue (field_bits));
477 template<
typename TFieldType>
479 uint64_t mask,
size_t shift,
480 const uint8_t *src, TOutputValueType *dst)
482 for (
size_t i = 0; i < num_values; ++i)
484 const uint8_t *field_ptr = src + i * address_step;
486 TFieldType field_value = ReadSwapped<TFieldType> (field_ptr);
487 uint64_t field_bits = mask & (field_value >> shift);
488 dst[i] =
static_cast<TOutputValueType
>(EffectiveValue (field_bits));
515 assert (
false &&
"Signed MaskeIntReg should be refused in constructor");
520 switch (current_reg_length)
523 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldBits<uint64_t>;
527 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldBits<uint32_t>;
531 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldBits<uint16_t>;
535 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldBits<uint8_t>;
548 switch (current_reg_length)
551 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<int64_t>;
555 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<int32_t>;
559 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<int16_t>;
563 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<int8_t>;
573 switch (current_reg_length)
576 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<uint64_t>;
580 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<uint32_t>;
584 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<uint16_t>;
588 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<uint8_t>;
600 switch (current_reg_length)
603 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<float64_t>;
607 current_array_getter = &CValueArrayAdapter::GetArrayOfFieldValues<float32_t>;
616 template<
typename TRawType>
622 template<
typename TFieldType>
681 #endif // VALUE_ARRAY_ADAPTER_H
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IBoolean
Interface for Boolean properties.
void GetArrayOfFieldValues(std::vector< TOutputValueType > &values)
static bool CheckAdvertisedCompatibility(TValueNodeType *base_value, IInteger *selector)
Check value/selector feature pair suitability for use with the adapter.
GENICAM_INTERFACE IInteger
Interface for integer properties.
static bool Convert(TSourceType src)
void GetArrayOfFieldBits(std::vector< TOutputValueType > &values)
bool IsValid() const
Check if the instance is valid and useable.
static TEffectiveValueType EffectiveValue(TRawType raw_value)
CFloatValueArray(IFloat *base_value, IInteger *selector)
virtual size_t find_first_of(const gcstring &str, size_t offset=0) const
CIntegerValueArray(IInteger *base_value, IInteger *selector)
Concrete value array implementation to be used with IInteger based target value nodes.
virtual void operator=(bool Value)
Set node value.
size_t current_num_values
ValueArrayInternals * pinternal
bool IsReadable(EAccessMode AccessMode)
Tests if readable.
virtual gcstring substr(size_t offset=0, size_t count=GCSTRING_NPOS) const
GENICAM_INTERFACE INodeMap
Interface to access the node map.
CBooleanValueArray(IBoolean *base_value, IInteger *selector)
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
GCBASE_API void Tokenize(const gcstring &str, gcstring_vector &tokens, const gcstring &delimiters=" ")
splits str input string into a list of tokens using the delimiter
void GetAllValues(std::vector< TOutputValueType > &values)
Get all values of the array.
ArrayGetterFunction current_array_getter
Base class wrapping internal implementation details of the value array adapter functionality.
Encapsulates a GenApi pointer dealing with the dynamic_cast automatically.
Main include file for using GenApi with smart pointers.
Adapter for accessing structured register known to include an array of selector-iterated values...
static TTargetType Convert(TSourceType src)
std::vector< TOutputValueType > GetAllValues()
Get all values of the array.
uint8_t * current_array_shadow
static void ExtractFieldBits_Swap(size_t num_values, size_t address_step, uint64_t mask, size_t shift, const uint8_t *src, TOutputValueType *dst)
uint64_t current_reg_length
Concrete value array implementation to be used with IFloat based target value nodes.
static TFieldType ReadSwapped(const void *ptr)
CValueArrayAdapter(TValueNodeType *base_value, IInteger *selector)
Creates a CValueArrayAdapter object.
uint64_t current_address_step
static void ExtractFieldValues_Noswap(size_t num_values, size_t address_step, const uint8_t *src, TOutputValueType *dst)
A string class which is a clone of std::string.
Concrete value array implementation to be used with IBoolean based target value nodes.
bool IsValid() const
true if the pointer is valid
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IFloat
Interface for float properties.
GenICam's exception class.
Definition of Lock classes.
static void ExtractFieldBits_Noswap(size_t num_values, size_t address_step, uint64_t mask, size_t shift, const uint8_t *src, TOutputValueType *dst)
GENICAM_INTERFACE GENAPI_DECL_ABSTRACT IValue
Interface for value properties.
Lexical analyzer for CIntSwissKnife.
static void ExtractFieldValues_Swap(size_t num_values, size_t address_step, const uint8_t *src, TOutputValueType *dst)
uint64_t current_base_address
virtual CLock & GetLock() const =0
Returns the lock which guards the node map.