aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcathook <b01902109@csie.ntu.edu.tw>2014-05-01 21:58:06 +0800
committercathook <b01902109@csie.ntu.edu.tw>2014-05-01 21:58:06 +0800
commit395a4bceaac30588963dacb8e006e9ebbe2ca6dd (patch)
tree6607a6fce44298a5b1c209932dbe4ee9f2f9dba1
parentb86d8a56110f4cc368212f6728e79a481f1187b2 (diff)
downloadmeow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar.gz
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar.bz2
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar.lz
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar.xz
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.tar.zst
meow-395a4bceaac30588963dacb8e006e9ebbe2ca6dd.zip
add OO
-rw-r--r--README.html2
-rw-r--r--_test/meowpp.h1
-rw-r--r--_test/meowpp_Colors.cpp24
-rw-r--r--meowpp/colors/RGB.h6
-rw-r--r--meowpp/colors/RGB.hpp32
-rw-r--r--meowpp/oo/ObjBase.h32
-rw-r--r--meowpp/oo/Properties.h61
-rw-r--r--meowpp/oo/Properties.hpp173
8 files changed, 317 insertions, 14 deletions
diff --git a/README.html b/README.html
index 379f6d9..aca9db5 100644
--- a/README.html
+++ b/README.html
@@ -3090,7 +3090,7 @@ E-Mail: cat.hook31894 ~在~ gmail.com
<div id="footnotes"><hr></div>
<div id="footer">
<div id="footer-text">
-Last updated 2014-05-01 05:12:39 CST
+Last updated 2014-05-01 21:55:51 CST
</div>
</div>
</body>
diff --git a/_test/meowpp.h b/_test/meowpp.h
index 8052f1a..94ff3ec 100644
--- a/_test/meowpp.h
+++ b/_test/meowpp.h
@@ -6,6 +6,7 @@
#include "meowpp/Usage.h"
#include "meowpp/oo/Register_Implement.h"
+#include "meowpp/oo/Properties.h"
extern meow::Usage usg, usg2;
extern int count;
diff --git a/_test/meowpp_Colors.cpp b/_test/meowpp_Colors.cpp
index 59f612f..ac740e0 100644
--- a/_test/meowpp_Colors.cpp
+++ b/_test/meowpp_Colors.cpp
@@ -16,9 +16,9 @@ TEST(Colors){
eps = 1e-8;
meow::messagePrintf(1, "rgb ---> hsl ---> rgb ---> hsl (eps = %e)", eps);
for(int i = 0; ok && i < 100000; i++){
- rgb.r(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
- rgb.g(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
- rgb.b(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
+ rgb.r(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
+ rgb.g(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
+ rgb.b(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
meow::RGB_to_HSL(rgb , &hsl );
meow::HSL_to_RGB(hsl , &rgb2);
meow::RGB_to_HSL(rgb2, &hsl2);
@@ -35,9 +35,9 @@ TEST(Colors){
eps = 1e-8;
meow::messagePrintf(1, "rgb ---> hsv ---> rgb ---> hsv (eps = %e)", eps);
for(int i = 0; ok && i < 100000; i++){
- rgb.r(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
- rgb.g(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
- rgb.b(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
+ rgb.r(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
+ rgb.g(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
+ rgb.b(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
meow::RGB_to_HSV(rgb , &hsv );
meow::HSV_to_RGB(hsv , &rgb2);
meow::RGB_to_HSV(rgb2, &hsv2);
@@ -93,9 +93,9 @@ TEST(Colors){
eps = 1e-3;
meow::messagePrintf(1, "rgb ---> yuv ---> rgb ---> yuv (eps = %e)", eps);
for(int i = 0; ok && i < 100000; i++){
- rgb.r(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
- rgb.g(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
- rgb.b(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
+ rgb.r(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.rMin(), rgb.rMax()));
+ rgb.g(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.gMin(), rgb.gMax()));
+ rgb.b(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, rgb.bMin(), rgb.bMax()));
meow::RGB_to_YUV(rgb , &yuv );
meow::YUV_to_RGB(yuv , &rgb2);
meow::RGB_to_YUV(rgb2, &yuv2);
@@ -111,9 +111,9 @@ TEST(Colors){
eps = 1e-8;
meow::messagePrintf(1, "hsl ---> hsv ---> hsl ---> hsv (eps = %e)", eps);
for(int i = 0; ok && i < 100000; i++){
- hsl.h(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, hsl.hMin(), hsl.hMax()));
- hsl.s(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, hsl.sMin(), hsl.sMax()));
- hsl.l(meow::ratioMapping(0, 1, 1.0 * rand() / RAND_MAX, hsl.lMin(), hsl.lMax()));
+ hsl.h(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, hsl.hMin(), hsl.hMax()));
+ hsl.s(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, hsl.sMin(), hsl.sMax()));
+ hsl.l(meow::ratioMapping(0.0, 1.0, 1.0 * rand() / RAND_MAX, hsl.lMin(), hsl.lMax()));
meow::HSL_to_HSV(hsl , &hsv );
meow::HSV_to_HSL(hsv , &hsl2);
meow::HSL_to_HSV(hsl2, &hsv2);
diff --git a/meowpp/colors/RGB.h b/meowpp/colors/RGB.h
index c7c03c1..803cdd9 100644
--- a/meowpp/colors/RGB.h
+++ b/meowpp/colors/RGB.h
@@ -2,6 +2,8 @@
#define colors_RGB_H_
#include <cstdlib>
+#include "../math.h"
+#include "../geo/Vector3D.h"
namespace meow{
template<class T>
@@ -32,6 +34,10 @@ namespace meow{
T b(T const& val);
T rgb(size_t i, T const& val);
T bgr(size_t i, T const& val);
+ T rgb(T const& __r, T const& __g, T const& __b);
+ T bgr(T const& __r, T const& __g, T const& __b);
+ Matrix <T> matrix() const;
+ Vector3D<T> vector() const;
};
class RGBf: public RGB<double>{
diff --git a/meowpp/colors/RGB.hpp b/meowpp/colors/RGB.hpp
index 1364814..0e0381d 100644
--- a/meowpp/colors/RGB.hpp
+++ b/meowpp/colors/RGB.hpp
@@ -6,6 +6,9 @@
#include "../math/utility.h"
+#include "../geo/Vector3D.h"
+#include "../math/Matrix.h"
+
namespace meow{
template<class T>
inline RGB<T>::RGB(){ }
@@ -47,7 +50,34 @@ namespace meow{
inline T RGB<T>::bgr(size_t i, T const& val){
return rgb(2 - i, val);
}
-
+ template<class T>
+ inline T RGB<T>::rgb(T const& __r, T const& __g, T const& __b){
+ r(__r);
+ g(__g);
+ b(__b);
+ }
+ template<class T>
+ inline T RGB<T>::bgr(T const& __b, T const& __g, T const& __r){
+ r(__r);
+ g(__g);
+ b(__b);
+ }
+ template<class T>
+ inline Matrix<T> RGB<T>::matrix() const{
+ static Matrix<T> ret(3, 1, T(0));
+ ret(0, 0) = r();
+ ret(1, 0) = g();
+ ret(2, 0) = b();
+ return ret;
+ }
+ template<class T>
+ inline Vector3D<T> RGB<T>::vector() const{
+ static Vector3D<T> ret;
+ ret(0) = r();
+ ret(1) = g();
+ ret(2) = b();
+ return ret;
+ }
inline RGBf::RGBf(): RGB(0.0, 0.0, 0.0){ }
diff --git a/meowpp/oo/ObjBase.h b/meowpp/oo/ObjBase.h
new file mode 100644
index 0000000..8bd0f1c
--- /dev/null
+++ b/meowpp/oo/ObjBase.h
@@ -0,0 +1,32 @@
+#ifndef oo_ObjBase_H__
+#define oo_ObjBase_H__
+
+#include <typeinfo>
+#include <string>
+
+namespace meow{
+ class ObjBase{
+ protected:
+ ObjBase(){ }
+ public:
+ virtual ~ObjBase(){ }
+ //
+ virtual char const* ctype() const{
+ static char const* ptr = typeid(*this).name();
+ return ptr;
+ }
+ virtual std::string type() const{
+ return std::string(ctype());
+ }
+ //
+ static char const* ctypeBase(){
+ static char const* ptr = typeid(ObjBase).name();
+ return ptr;
+ }
+ static std::string typeBase(){
+ return std::string(ctypeBase());
+ }
+ };
+}
+
+#endif // oo_ObjBase_H__
diff --git a/meowpp/oo/Properties.h b/meowpp/oo/Properties.h
new file mode 100644
index 0000000..f19e300
--- /dev/null
+++ b/meowpp/oo/Properties.h
@@ -0,0 +1,61 @@
+#ifndef oo_Properties_H__
+#define oo_Properties_H__
+
+#include "ObjBase.h"
+
+#include <map>
+#include <queue>
+
+#include <cstdlib>
+
+namespace meow{
+ class Properties: public ObjBase{
+ private:
+ struct Property{
+ ObjBase* _pointer;
+ ssize_t _counter;
+ //
+ Property(ObjBase* __pointer, bool __autoRemove);
+ Property(Property const& __property);
+ ~Property();
+ //
+ bool attach();
+ bool detach();
+ };
+ //
+ std::map<size_t, Property*> _properties;
+ std::map<std::string, size_t> _index;
+ std::queue<size_t> _freeIndex;
+ //
+ size_t newIndex(std::string const& __name);
+ void delIndex(size_t __index);
+ void detach(size_t __index);
+ public:
+ Properties();
+ Properties(Properties const& __p);
+ ~Properties();
+ //
+ void clear();
+ Properties& copy (Properties const& __p);
+ //
+ size_t size () const;
+ bool empty() const;
+ //
+ bool chg(size_t __index, ObjBase* __pointer, bool __autoRemove);
+ bool add(std::string __name , ObjBase* __pointer, bool __autoRemove);
+ bool del(size_t __index);
+ bool del(std::string __name );
+ ObjBase* get(size_t __index) const;
+ ObjBase* get(std::string __name ) const;
+ ssize_t getIndex(ObjBase* __pointer) const;
+ std::string getName (ObjBase* __pointer) const;
+ //
+ Properties& operator=(Properties const& __p);
+ ObjBase* operator()(size_t __index) const;
+ ObjBase* operator()(std::string __name ) const;
+ };
+}
+
+#include "Properties.hpp"
+
+#endif // oo_Properties_H__
diff --git a/meowpp/oo/Properties.hpp b/meowpp/oo/Properties.hpp
new file mode 100644
index 0000000..90d9805
--- /dev/null
+++ b/meowpp/oo/Properties.hpp
@@ -0,0 +1,173 @@
+#include "Properties.h"
+
+#include <map>
+#include <queue>
+
+
+namespace meow{
+ inline Properties::Property::Property(ObjBase* __pointer, bool __autoRemove):
+ _pointer(__pointer),
+ _counter(__autoRemove ? -1 : 1){
+ }
+ inline Properties::Property::Property(Property const& __property):
+ _pointer(__property._pointer),
+ _counter(__property._counter){
+ }
+ inline Properties::Property::~Property(){
+ }
+ inline bool Properties::Property::attach(){
+ if(_pointer == NULL || _counter <= 0) return false;
+ _counter++;
+ return true;
+ }
+ inline bool Properties::Property::detach(){
+ if(_pointer == NULL || _counter <= 0) return false;
+ _counter--;
+ if(_counter <= 0){
+ delete _pointer;
+ _pointer = NULL;
+ }
+ return true;
+ }
+ ////////////////////////////////////////////////////////////////////
+ inline size_t Properties::newIndex(std::string const& __name){
+ size_t i;
+ if(_freeIndex.size() > 0){
+ i = _freeIndex.front();
+ _freeIndex.pop();
+ }else{
+ i = size();
+ }
+ _index[__name] = i;
+ return i;
+ }
+ inline void Properties::delIndex(size_t __index){
+ _properties.erase(__index);
+ for(std::map<std::string, size_t>::iterator it = _index.begin();
+ it != _index.end();
+ it++){
+ if(it->second == __index){
+ _index.erase(it);
+ break;
+ }
+ }
+ _freeIndex.push(__index);
+ }
+ inline void Properties::detach(size_t __index){
+ _properties[__index]->detach();
+ if(_properties[__index]->_counter == 0){
+ delete _properties[__index];
+ }
+ _properties[__index] = NULL;
+ }
+ inline Properties::Properties(){
+ }
+ inline Properties::Properties(Properties const& __p){
+ copy(__p);
+ }
+ inline Properties::~Properties(){
+ clear();
+ }
+ inline void Properties::clear(){
+ for(std::map<size_t, Property*>::iterator it = _properties.begin();
+ it != _properties.end();
+ it++){
+ it->second->detach();
+ }
+ _properties.clear();
+ _index .clear();
+ while(!_freeIndex.empty())
+ _freeIndex.pop();
+ }
+ inline Properties& Properties::copy(Properties const& __p){
+ clear();
+ _properties = ((Properties&)__p)._properties;
+ _index = ((Properties&)__p)._index;
+ _freeIndex = ((Properties&)__p)._freeIndex;
+ for(std::map<size_t, Property*>::iterator it = _properties.begin();
+ it != _properties.end();
+ it++){
+ it->second->attach();
+ }
+ return *this;
+ }
+ inline size_t Properties::size() const{
+ return (_properties.size());
+ }
+ inline bool Properties::empty() const{
+ return (size() == 0u);
+ }
+ inline bool Properties::chg(size_t __index,
+ ObjBase* __pointer,
+ bool __autoRemove){
+ if(get(__index) == NULL)
+ return false;
+ detach(__index);
+ _properties[__index] = new Property(__pointer, __autoRemove);
+ return true;
+ }
+ inline bool Properties::add(std::string __name ,
+ ObjBase* __pointer,
+ bool __autoRemove){
+ if(get(__name) != NULL)
+ del(__name);
+ _properties[newIndex(__name)] = new Property(__pointer, __autoRemove);
+ return true;
+ }
+ inline bool Properties::del(size_t __index){
+ if(get(__index) == NULL){
+ return false;
+ }
+ detach(__index);
+ delIndex(__index);
+ return true;
+ }
+ inline bool Properties::del(std::string __name){
+ if(get(__name) == NULL){
+ return false;
+ }
+ return del(_index[__name]);
+ }
+ inline ObjBase* Properties::get(size_t __index) const{
+ std::map<size_t, Property*>::const_iterator i = _properties.find(__index);
+ if(i == _properties.end()) return NULL;
+ return (ObjBase*)(i->second->_pointer);
+ }
+ inline ObjBase* Properties::get(std::string __name) const{
+ std::map<std::string, size_t>::const_iterator i = _index.find(__name);
+ if(i == _index.end()) return NULL;
+ return get(i->second);
+ }
+ inline ssize_t Properties::getIndex(ObjBase* __pointer) const{
+ for(std::map<size_t, Property*>::const_iterator it = _properties.begin();
+ it != _properties.end();
+ it++){
+ if(it->second->_pointer == __pointer){
+ return it->first;
+ }
+ }
+ return -1;
+ }
+ inline std::string Properties::getName(ObjBase* __pointer) const{
+ ssize_t t = getIndex(__pointer);
+ if(t < 0) return std::string();
+ for(std::map<std::string, size_t>::const_iterator it = _index.begin();
+ it != _index.end();
+ it++){
+ if(it->second == (size_t)t){
+ if(it == _index.end()) return std::string();
+ return it->first;
+ }
+ }
+ return std::string();
+ }
+ inline Properties& Properties::operator=(Properties const& __p){
+ return copy(__p);
+ }
+ inline ObjBase* Properties::operator()(size_t __index) const{
+ return get(__index);
+ }
+ inline ObjBase* Properties::operator()(std::string __name) const{
+ return get(__name);
+ }
+};