Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
vector.h
1 
2 /***************************************************************************
3  * vector.h - Column Vector
4  *
5  * Created: Wed April 02 14:03:32 2008
6  * Copyright 2008 Daniel Beck
7  *
8  ****************************************************************************/
9 
10 /* This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version. A runtime exception applies to
14  * this software (see LICENSE.GPL_WRE file mentioned below for details).
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU Library General Public License for more details.
20  *
21  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
22  */
23 
24 #ifndef __GEOMETRY_VECTOR_H_
25 #define __GEOMETRY_VECTOR_H_
26 
27 #include <ostream>
28 
29 namespace fawkes {
30 
31 class Vector
32 {
33  public:
34  Vector(unsigned int size = 3, float* elems = 0, bool manage_memory = true);
35  Vector(const Vector& v);
36  virtual ~Vector();
37 
38  unsigned int size() const;
39  void set_size(unsigned int size);
40 
41  float* data_ptr() { return m_data; }
42  const float* data_ptr() const { return m_data; }
43 
44  float get(unsigned int d) const;
45  float& get(unsigned int d);
46  void set(unsigned int d, float v);
47 
48  float x() const;
49  float& x();
50  void x(float x);
51 
52  float y() const;
53  float& y();
54  void y(float y);
55 
56  float z() const;
57  float& z();
58  void z(float z);
59 
60  float operator[](unsigned int d) const;
61  float& operator[](unsigned int d);
62 
63  Vector operator*(const float& f) const;
64  Vector& operator*=(const float& f);
65  Vector operator/(const float& f) const;
66  Vector& operator/=(const float& f);
67 
68  float operator*(const Vector& v) const;
69 
70  Vector operator+(const Vector& v) const;
71  Vector& operator+=(const Vector& v);
72  Vector operator-(const Vector& v) const;
73  Vector& operator-=(const Vector& v);
74  Vector& operator=(const Vector& v);
75 
76  bool operator==(const Vector& v);
77 
78  void print_info(const char* name = 0) const;
79 
80  friend std::ostream& operator<<(std::ostream& stream, const Vector &v);
81 
82  private:
83  unsigned int m_size;
84  float* m_data;
85  bool m_manage_memory;
86 };
87 
88 } // end namespace fawkes
89 
90 #endif /* __GEOMETRY_VECTOR_H_ */