GEOS: NodeBase.h Source File

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List

# NodeBase.h

    00001 /**********************************************************************
    00002  * $Id: NodeBase.h 2556 2009-06-06 22:22:28Z strk $
    00003  *
    00004  * GEOS - Geometry Engine Open Source
    00005  * http://geos.refractions.net
    00006  *
    00007  * Copyright (C) 2006 Refractions Research Inc.
    00008  *
    00009  * This is free software; you can redistribute and/or modify it under
    00010  * the terms of the GNU Lesser General Public Licence as published
    00011  * by the Free Software Foundation.
    00012  * See the COPYING file for more information.
    00013  *
    00014  **********************************************************************
    00015  *
    00016  * Last port: index/quadtree/NodeBase.java rev 1.9 (JTS-1.10)
    00017  *
    00018  **********************************************************************/
    00019
    00020 #ifndef GEOS_IDX_QUADTREE_NODEBASE_H
    00021 #define GEOS_IDX_QUADTREE_NODEBASE_H
    00022
    00023 #include <geos/export.h>
    00024 #include <vector>
    00025 #include <string>
    00026
    00027 // Forward declarations
    00028 namespace geos {
    00029         namespace geom {
    00030                 class Coordinate;
    00031                 class Envelope;
    00032         }
    00033         namespace index {
    00034                 class ItemVisitor;
    00035                 namespace quadtree {
    00036                         class Node;
    00037                 }
    00038         }
    00039 }
    00040
    00041 namespace geos {
    00042 namespace index { // geos::index
    00043 namespace quadtree { // geos::index::quadtree
    00044
    00050 class GEOS_DLL NodeBase {
    00051
    00052 private:
    00053
    00054         void visitItems(const geom::Envelope* searchEnv,
    00055                         ItemVisitor& visitor);
    00056
    00057 public:
    00058
    00059         static int getSubnodeIndex(const geom::Envelope *env,
    00060                         const geom::Coordinate& centre);
    00061
    00062         NodeBase();
    00063
    00064         virtual ~NodeBase();
    00065
    00066         std::vector<void*>& getItems();
    00067
    00070         void add(void* item);
    00071
    00073         std::vector<void*>& addAllItems(std::vector<void*>& resultItems) const;
    00074
    00075         virtual void addAllItemsFromOverlapping(const geom::Envelope& searchEnv,
    00076                         std::vector<void*>& resultItems) const;
    00077
    00078         unsigned int depth() const;
    00079
    00080         unsigned int size() const;
    00081
    00082         unsigned int getNodeCount() const;
    00083
    00084         virtual std::string toString() const;
    00085
    00086         virtual void visit(const geom::Envelope* searchEnv, ItemVisitor& visitor);
    00087
    00095         bool remove(const geom::Envelope* itemEnv, void* item);
    00096
    00097         bool hasItems() const;
    00098
    00099         bool hasChildren() const;
    00100
    00101         bool isPrunable() const;
    00102
    00103 protected:
    00104
    00106         std::vector<void*> items;
    00107
    00118         Node* subnode[4];
    00119
    00120         virtual bool isSearchMatch(const geom::Envelope& searchEnv) const=0;
    00121 };
    00122
    00123
    00124 // INLINES, To be moved in NodeBase.inl
    00125
    00126 inline bool
    00127 NodeBase::hasChildren() const
    00128 {
    00129         for (int i = 0; i < 4; i++)
    00130                 if (subnode[i]) return true;
    00131         return false;
    00132 }
    00133
    00134 inline bool
    00135 NodeBase::isPrunable() const
    00136 {
    00137         return ! (hasChildren() || hasItems());
    00138 }
    00139
    00140 inline bool
    00141 NodeBase::hasItems() const
    00142 {
    00143         return ! items.empty();
    00144 }
    00145
    00146 } // namespace geos::index::quadtree
    00147 } // namespace geos::index
    00148 } // namespace geos
    00149
    00150 #endif // GEOS_IDX_QUADTREE_NODEBASE_H
    00151
    00152 /**********************************************************************
    00153  * $Log$
    00154  * Revision 1.1  2006/03/22 12:22:50  strk
    00155  * indexQuadtree.h split
    00156  *
    00157  **********************************************************************/
    00158