source: flair-src/trunk/lib/FlairCore/src/Vector3Ddata.cpp @ 15

Last change on this file since 15 was 15, checked in by Bayard Gildas, 5 years ago

sources reformatted with flair-format-dir script

File size: 2.2 KB
Line 
1// %flair:license{
2// This file is part of the Flair framework distributed under the
3// CECILL-C License, Version 1.0.
4// %flair:license}
5//  created:    2014/11/26
6//  filename:   Vector3Ddata.cpp
7//
8//  author:     Guillaume Sanahuja
9//              Copyright Heudiasyc UMR UTC/CNRS 7253
10//
11//  version:    $Id: $
12//
13//  purpose:    Class defining a 3D vector and a io_data
14//
15//
16/*********************************************************************/
17
18#include "Vector3Ddata.h"
19#include <string.h>
20
21#define X 0
22#define Y 1
23#define Z 2
24
25using std::string;
26
27namespace flair {
28namespace core {
29
30/*! \class Vector3DdataElement
31 */
32class Vector3DdataElement : public IODataElement {
33public:
34  Vector3DdataElement(const Vector3Ddata *data, string name, uint32_t elem)
35      : IODataElement(data, name) {
36    this->data = data;
37    this->elem = elem;
38    size = 4;
39  }
40
41  ~Vector3DdataElement() {}
42
43  void CopyData(char *dst) const {
44    float value;
45    data->GetMutex();
46    switch (elem) {
47    case X:
48      value = data->x;
49      break;
50    case Y:
51      value = data->y;
52      break;
53    case Z:
54      value = data->z;
55      break;
56    default:
57      data->Err("type not handled\n");
58      value = 0;
59      break;
60    }
61    data->ReleaseMutex();
62
63    memcpy(dst, &value, sizeof(float));
64  }
65
66  ScalarType const &GetDataType() const { return dataType; }
67
68private:
69  const Vector3Ddata *data;
70  uint32_t elem;
71  FloatType dataType;
72};
73
74Vector3Ddata::Vector3Ddata(const Object *parent, string name, float x, float y,
75                           float z, uint32_t n)
76    : io_data(parent, name, n), Vector3D(x, y, z) {}
77
78Vector3Ddata::~Vector3Ddata() {}
79
80void Vector3Ddata::CopyDatas(char *dst) const {
81  GetMutex();
82  memcpy(dst, &x, sizeof(float));
83  memcpy(dst + sizeof(float), &y, sizeof(float));
84  memcpy(dst + 2 * sizeof(float), &z, sizeof(float));
85  ReleaseMutex();
86}
87
88IODataElement *Vector3Ddata::XElement(void) const {
89  return new Vector3DdataElement(this, "x", X);
90}
91
92IODataElement *Vector3Ddata::YElement(void) const {
93  return new Vector3DdataElement(this, "y", Y);
94}
95
96IODataElement *Vector3Ddata::ZElement(void) const {
97  return new Vector3DdataElement(this, "z", Z);
98}
99
100} // end namespace core
101} // end namespace flair
Note: See TracBrowser for help on using the repository browser.