[nemiver] Add new range type



commit f8ef88467e34d4c380c1f053f96a277af2d6f8c0
Author: Dodji Seketeli <dodji redhat com>
Date:   Sat Apr 10 15:45:10 2010 +0200

    Add new range type
    
    	* src/common/nmv-range.h: New range type declaration/definition.
    	* src/common/Makefile.am: Add it to the build system.

 src/common/Makefile.am |    1 +
 src/common/nmv-range.h |   68 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+), 0 deletions(-)
---
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index 562aeb7..2c8b835 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -6,6 +6,7 @@ nmv-api-macros.h \
 nmv-namespace.h \
 nmv-ustring.h \
 nmv-address.h \
+nmv-range.h \
 nmv-str-utils.h \
 nmv-libxml-utils.h \
 nmv-safe-ptr-utils.h \
diff --git a/src/common/nmv-range.h b/src/common/nmv-range.h
new file mode 100644
index 0000000..1bd40e1
--- /dev/null
+++ b/src/common/nmv-range.h
@@ -0,0 +1,68 @@
+// Author: Dodji Seketeli
+/*
+ *This file is part of the Nemiver project
+ *
+ *Nemiver is free software; you can redistribute
+ *it and/or modify it under the terms of
+ *the GNU General Public License as published by the
+ *Free Software Foundation; either version 2,
+ *or (at your option) any later version.
+ *
+ *Nemiver is distributed in the hope that it will
+ *be useful, but WITHOUT ANY WARRANTY;
+ *without even the implied warranty of
+ *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *See the GNU General Public License for more details.
+ *
+ *You should have received a copy of the
+ *GNU General Public License along with Nemiver;
+ *see the file COPYING.
+ *If not, write to the Free Software Foundation,
+ *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ *See COPYRIGHT file copyright information.
+ */
+#ifndef __NEMIVER_RANGE_H__
+#define __NEMIVER_RANGE_H__
+
+#include "nmv-namespace.h"
+#include "nmv-api-macros.h"
+
+NEMIVER_BEGIN_NAMESPACE (nemiver)
+NEMIVER_BEGIN_NAMESPACE (common)
+
+class Range {
+    size_t m_min;
+    size_t m_max;
+
+public:
+    Range (size_t a_min = 0, size_t a_max = 0) :
+        m_min (a_min),
+        m_max (a_max)
+    {
+    }
+
+    size_t min () const {return m_min;}
+    void min (int a) {m_min = a;}
+    size_t max () const {return m_max;}
+    void max (int a) {m_max = a;}
+    bool contains (size_t a_value) const
+    {
+        return (a_value >= m_min && a_value <= m_max);
+    }
+    void extend (size_t a_value)
+    {
+        if (!contains (a_value)) {
+            if (a_value < m_min)
+                m_min = a_value;
+            else
+                m_max = a_value;
+        }
+    }
+};
+
+NEMIVER_END_NAMESPACE (common)
+NEMIVER_END_NAMESPACE (nemiver)
+
+#endif // __NMV_RANGE_H__
+



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]