Commit 55bcc877 authored by ahoms's avatar ahoms
Browse files

* added Exceptions and more SizeUtils functionalities


git-svn-id: https://scm.blissgarden.org/svn/lima/trunk@11 45c4679d-1946-429d-baad-37912b19538b
parent 9ec7aa82
......@@ -30,6 +30,6 @@ enum BufferMode {
Linear, Circular,
};
} // lima
} // namespace lima
#endif // CONSTANTS_H
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#include <string>
namespace lima
{
enum Layer {
Common, Control, Hardware,
};
enum ErrorType {
InvalidValue, NotSupported, Error,
};
class Exception
{
public:
typedef std::string String;
Exception(Layer layer, ErrorType err_type, String err_desc,
String file_name, String funct_name, int line_nr);
private:
Layer m_layer;
ErrorType m_err_type;
String m_err_desc;
String m_file_name;
String m_funct_name;
int m_line_nr;
};
#define LIMA_EXC(layer, err_type, err_desc) \
Exception(layer, err_type, err_desc, __FILE__, __FUNCTION__, __LINE__)
#define LIMA_COM_EXC(err_type, err_desc) \
LIMA_EXC(Common, err_type, err_desc)
#define LIMA_CTL_EXC(err_type, err_desc) \
LIMA_EXC(Control, err_type, err_desc)
#define LIMA_HW_EXC(err_type, err_desc) \
LIMA_EXC(Hardware, err_type, err_desc)
} // namespace lima
#endif // EXCEPTIONS_H
......@@ -2,6 +2,7 @@
#define SIZEUTILS_H
#include "Constants.h"
#include "Exceptions.h"
namespace lima
{
......@@ -52,26 +53,22 @@ class Point
inline Point operator +(const Point& p1, const Point& p2)
{
Point p = p1;
return p += p2;
return Point(p1) += p2;
}
inline Point operator -(const Point& p1, const Point& p2)
{
Point p = p1;
return p -= p2;
return Point(p1) -= p2;
}
inline Point operator *(const Point& p1, const Point& p2)
{
Point p = p1;
return p *= p2;
return Point(p1) *= p2;
}
inline Point operator /(const Point& p1, const Point& p2)
{
Point p = p1;
return p /= p2;
return Point(p1) /= p2;
}
inline bool operator ==(const Point& p1, const Point& p2)
......@@ -95,9 +92,9 @@ inline bool operator !=(const Point& p1, const Point& p2)
class Size
{
public:
Size() {}
Size() : m_xy() {}
Size(int w, int h) : m_xy(w, h) {}
Size(const Point& w_h) : m_xy(w_h) {}
Size(const Point& p) : m_xy(p) {}
Size(const Size& s) : m_xy(s.m_xy) {}
int getWidth() const
......@@ -106,14 +103,93 @@ class Size
int getHeight() const
{ return m_xy.y; }
bool isEmpty() const
{ return m_xy.getArea() == 0; }
operator Point() const
{ return m_xy; }
Size& operator =(const Point& p)
{ m_xy = p; return *this; }
Size& operator +=(const Point& p)
{ m_xy += p; return *this; }
Size& operator -=(const Point& p)
{ m_xy -= p; return *this; }
Size& operator *=(const Point& p)
{ m_xy *= p; return *this; }
Size& operator /=(const Point& p)
{ m_xy /= p; return *this; }
private:
Point m_xy;
};
/*******************************************************************
* \class Size
* \brief Basic rectangle size class
*
* This class helps managing the size of rectangular objects
*******************************************************************/
class Bin
{
public:
Bin() : m_xy(1) {}
Bin(int x, int y) : m_xy(checkValid(Point(x, y))) {}
Bin(const Point& p) : m_xy(checkValid(p)) {}
Bin(const Bin& b) : m_xy(b.m_xy) {}
int getX() const
{ return m_xy.x; }
int getY() const
{ return m_xy.y; }
operator Point() const
{ return m_xy; }
Bin& operator =(const Point& p)
{ m_xy = checkValid(p); return *this; }
Bin& operator *=(const Point& p)
{ m_xy = checkValid(m_xy * p); return *this; }
Bin& operator /=(const Point& p)
{ m_xy = checkValid(m_xy / p); return *this; }
private:
static bool isValid(int i);
static Point checkValid(const Point& p);
Point m_xy;
};
inline bool Bin::isValid(int i)
{
return (i > 0);
}
inline Point Bin::checkValid(const Point& p)
{
if (!(isValid(p.x) && isValid(p.y)))
throw LIMA_COM_EXC(InvalidValue, "Invalid binning");
return p;
}
/*******************************************************************
* \class FrameDim
* \brief Class holding the Size and ImageType of a frame
*
* This class contains the X, Y and Z dimensions of a frame. For
* practical reasons, it also contains the depth in bytes.
*******************************************************************/
class FrameDim
{
......@@ -124,6 +200,7 @@ class FrameDim
const Size& getSize() const;
ImageType getImageType() const;
int getDepth() const;
int getMemSize() const;
static int getImageTypeBpp(ImageType type);
static int getImageTypeDepth(ImageType type);
......@@ -136,8 +213,38 @@ class FrameDim
int m_depth;
};
inline const Size& FrameDim::getSize() const
{
return m_size;
}
inline ImageType FrameDim::getImageType() const
{
return m_type;
}
inline int FrameDim::getDepth() const
{
return m_depth;
}
int FrameDim::getMemSize() const
{
return Point(m_size).getArea() * m_depth;
}
inline bool operator ==(const FrameDim& f1, const FrameDim& f2)
{
return ((f1.getSize() == f2.getSize()) &&
(f1.getDepth() == f2.getDepth()));
}
inline bool operator !=(const FrameDim& f1, const FrameDim& f2)
{
return !(f1 == f2);
}
} // lima
} // namespace lima
#endif // SIZEUTILS_H
......@@ -3,7 +3,7 @@
using namespace lima;
/*******************************************************************
* \brief Aligns the Point to the nearest boundary another Point
* \brief Aligns the Point to the nearest boundary of another Point
*
* This method aligns the point to the nearest boundary that is
* a multiple of another Point. The align_dir parameter controls
......@@ -35,21 +35,6 @@ FrameDim::FrameDim(int width, int height, ImageType type)
m_depth = getImageTypeDepth(type);
}
const Size& FrameDim::getSize() const
{
return m_size;
}
ImageType FrameDim::getImageType() const
{
return m_type;
}
int FrameDim::getDepth() const
{
return m_depth;
}
int FrameDim::getImageTypeBpp(ImageType type)
{
switch (type) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment