00001 // -*- C++ -*- 00002 // 00003 // This file is part of libgvectors. 00004 // libgvectors is a C++ library intended for visualizing mathematical vectors. 00005 // Copyright (C) 2007 Rafael Ostertag 00006 // 00007 // This program is free software; you can redistribute it and/or 00008 // modify it under the terms of the GNU General Public License 00009 // as published by the Free Software Foundation; either version 2 00010 // of the License, or (at your option) any later version. 00011 // 00012 // This program is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with this program; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 00020 // USA. 00021 // 00022 // $Id: vstorefuncs_8h-source.html,v 1.1 2007-09-08 19:02:38 rafi Exp $ 00023 // 00024 // File: vstorefuncs.h 00025 // Author: Rafael Ostertag 00026 // 00027 // Created on August 2, 2007, 12:36 AM 00028 // 00029 00041 #ifndef _VSTOREFUNCS_H 00042 #define _VSTOREFUNCS_H 00043 00044 #include <functional> 00045 #include <map> 00046 00047 namespace GVectors { 00048 00049 // Forward declaration. 00050 class VStoreItem; 00051 // Forward declaration. 00052 class Rotation; 00053 // Forward declaration. 00054 class FileWriter; 00055 00061 class VDelete { 00062 private: 00068 inline VDelete& operator=(const VDelete&) {return *this;} 00069 public: 00075 inline explicit VDelete() {} 00081 inline VDelete(const VDelete&){}; 00087 inline ~VDelete() {} 00089 void operator()(VStoreItem* i) const; 00090 }; 00091 00097 class VSetOrigin { 00098 private: 00104 const Coordinates& origin; 00110 inline VSetOrigin& operator=(const VSetOrigin&) {return *this;} 00111 public: 00119 inline explicit VSetOrigin(const Coordinates &c) : origin(c) {} 00127 inline VSetOrigin(const VSetOrigin& t) : origin(t.origin) {} 00133 inline ~VSetOrigin() {} 00135 void operator()(VStoreItem *i) const; 00136 }; 00137 00143 class VSetScale { 00144 private: 00150 double& scale; 00156 inline VSetScale& operator=(const VSetScale&) { return *this; } 00157 public: 00165 inline explicit VSetScale(double& sc) : scale(sc) {} 00173 inline VSetScale(const VSetScale& t) : scale(t.scale) {} 00179 inline ~VSetScale() {} 00181 void operator()(VStoreItem *i) const; 00182 }; 00183 00191 class VSetArrowLength { 00192 private: 00198 double& arrowlength; 00204 inline const VSetArrowLength& operator=(const VSetArrowLength&) { return *this; } 00205 public: 00213 inline explicit VSetArrowLength(double& arl) : arrowlength(arl) {} 00221 inline VSetArrowLength(const VSetArrowLength& t) : arrowlength(t.arrowlength) {} 00227 inline ~VSetArrowLength() {} 00229 void operator()(VStoreItem *i) const; 00230 }; 00231 00237 class VSetRotation { 00238 private: 00244 const Rotation& rotation; 00250 inline const VSetRotation& operator=(const VSetRotation&) { return *this; } 00251 public: 00260 inline explicit VSetRotation(const Rotation& r) : rotation(r) {} 00268 inline VSetRotation(const VSetRotation& r) : rotation(r.rotation) {} 00274 inline ~VSetRotation() {} 00276 void operator()(VStoreItem *i) const; 00277 }; 00278 00285 class VDraw { 00286 private: 00293 Drawer& drawer; 00299 inline VDraw& operator=(const VDraw&) {return *this;} 00300 public: 00308 inline explicit VDraw(Drawer& d) : drawer(d) {} 00316 inline VDraw(const VDraw& t) : drawer(t.drawer) {} 00322 inline ~VDraw() {}; 00324 void operator()(VStoreItem *i) const; 00325 }; 00326 00333 class VRemoveItemByAddress { 00334 private: 00340 const VStoreItem* item; 00346 inline const VRemoveItemByAddress& operator=(const VRemoveItemByAddress&) { return *this; } 00347 00348 public: 00356 explicit VRemoveItemByAddress(const VStoreItem* i) : item(i) {} 00365 inline VRemoveItemByAddress(const VRemoveItemByAddress& c) : item(c.item) {} 00371 inline ~VRemoveItemByAddress() {} 00387 inline bool operator()(const VStoreItem* a) { 00388 if (a==item) 00389 return true; 00390 return false; 00391 } 00392 }; 00393 00399 class GetMinMax { 00400 private: 00406 Coordinates max; 00412 Coordinates min; 00413 00414 public: 00416 explicit GetMinMax(); 00424 inline GetMinMax(const GetMinMax& gmm) : max(gmm.max), min(gmm.min) {} 00430 inline ~GetMinMax() {;} 00432 const GetMinMax& operator=(const GetMinMax& gmm); 00434 void operator()(const Coordinates& f, const Coordinates& t); 00436 void reset(); 00437 00446 inline Coordinates getMax() const { return max; } 00455 inline Coordinates getMin() const { return min; } 00456 }; 00457 00463 class ForEachMinMax { 00464 private: 00471 GetMinMax& getminmax; 00472 00473 public: 00481 inline explicit ForEachMinMax(GetMinMax& gmm) : getminmax(gmm) {;} 00489 inline ForEachMinMax(const ForEachMinMax& mm) : getminmax(mm.getminmax) {;} 00491 const ForEachMinMax& operator=(const ForEachMinMax& femm); 00497 inline ~ForEachMinMax() {;} 00499 void operator()(VStoreItem* i); 00508 inline GetMinMax get() const { return getminmax; } 00514 inline void reset() { getminmax.reset(); } 00515 }; 00516 00524 class SyncLookup { 00525 private: 00532 std::map<gvid_t, VStoreItem*>& lookup_ref; 00533 00539 inline SyncLookup& operator=(const SyncLookup&) {return *this;} 00540 00541 public: 00549 inline explicit SyncLookup(std::map<gvid_t, VStoreItem*>& lr) 00550 : lookup_ref(lr) { /* Empty */ } 00556 inline ~SyncLookup() { /* Empty */ } 00564 inline SyncLookup(const SyncLookup& sl) 00565 : lookup_ref(sl.lookup_ref) { /* Empty */ } 00567 void operator()(gvid_t id) const; 00568 }; 00569 00580 class FindTopLevel : public std::unary_function<VStoreItem*, bool> { 00581 private: 00587 gvid_t id_to_find; 00588 public: 00596 inline explicit FindTopLevel(gvid_t id) : id_to_find(id) { /* Empty */ } 00598 bool operator() (const VStoreItem* vsi) const; 00599 }; 00600 00606 class CountItems { 00607 private: 00613 vssize_t items; 00614 00615 public: 00621 inline explicit CountItems() : items(0) { ; } 00629 inline explicit CountItems(vssize_t sv) : items(sv) { ; } 00635 inline ~CountItems() { ; } 00643 inline CountItems(const CountItems& ci) : items(ci.items) { ; } 00653 inline const CountItems& operator=(const CountItems& ci) { 00654 items = ci.items; 00655 return *this; 00656 } 00664 inline vssize_t amount() const { return items; } 00670 inline void reset() { items = 0; } 00672 void operator() (const VStoreItem* vsi); 00682 inline CountItems operator+(const CountItems& ci) const { 00683 return CountItems(items+ci.items); 00684 } 00695 inline const CountItems& operator+=(const CountItems& ci) { 00696 items += ci.items; 00697 return *this; 00698 } 00699 }; 00700 00707 class SaveItems { 00708 private: 00714 vslevel_t level; 00721 FileWriter& filewriter; 00722 00728 inline const SaveItems& operator=(const SaveItems&) { return *this; } 00729 00730 public: 00740 inline explicit SaveItems(vslevel_t l, FileWriter& fw) : level(l), filewriter(fw) { ; } 00748 inline SaveItems(const SaveItems& si) : level(si.level), filewriter(si.filewriter) { ; } 00754 inline ~SaveItems() { ; } 00756 void operator() (const VStoreItem* vsi) const; 00757 }; 00758 } 00759 00760 #endif /* _VSTOREFUNCS_H */
1.4.7