00001 // tutorial places class -*- C++ -*- 00002 // $Id: places.h,v 1.10 2004/01/28 21:21:10 roger Exp $ 00003 // 00004 // Copyright (C) 2003 Roger Leigh <rleigh@debian.org> 00005 // 00006 // 00007 // All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions 00011 // are met: 00012 // 00013 // * Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // * Redistributions in binary form must reproduce the above 00016 // copyright notice, this list of conditions and the following 00017 // disclaimer in the documentation and/or other materials provided 00018 // with the distribution. 00019 // * Neither the name of the author, nor the names of other 00020 // contributors may be used to endorse or promote products derived 00021 // from this software without specific prior written permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00024 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00025 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 00028 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00030 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00031 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00032 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00033 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00034 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00035 // SUCH DAMAGE. 00036 // 00038 00039 #ifndef TUTORIAL_PLACES_H 00040 #define TUTORIAL_PLACES_H 00041 00042 #include <string> 00043 #include <vector> 00044 00045 #include <pqxx-object/field.h> 00046 #include <pqxx-object/row.h> 00047 #include <pqxx-object/table.h> 00048 00057 class Place : public pqxxobject::row<Place> 00058 { 00059 public: 00061 Place(); 00062 00068 Place(const std::string& name, 00069 const std::string& gridref); 00070 00072 virtual ~Place(); 00073 00078 int get_id() const; 00079 00084 const std::string& get_name() const; 00085 00090 void set_name(const std::string& name); 00091 00096 const std::string& get_gridref() const; 00097 00102 void set_gridref(const std::string& gridref); 00103 00104 protected: 00108 virtual void insert_impl(pqxxobject::transaction& tran); 00109 00113 virtual void update_impl(pqxxobject::transaction& tran); 00114 00118 virtual void erase_impl(pqxxobject::transaction& tran); 00119 00123 virtual void refresh_impl(pqxxobject::transaction& tran); 00124 00125 virtual void convert_impl(pqxx::result::const_iterator row, 00126 pqxxobject::transaction& tran); 00127 00128 private: 00130 pqxxobject::field<int> m_id; 00132 pqxxobject::field<std::string> m_name; 00134 pqxxobject::field<std::string> m_gridref; 00135 00136 friend class pqxxobject::row<Place>; 00137 00138 }; // class Place 00139 00147 class PlaceTable : public pqxxobject::table<Place> 00148 { 00149 public: 00151 typedef pqxxobject::table<Place> table_base; 00152 00157 PlaceTable(pqxxobject::transaction& tran); 00158 00160 virtual ~PlaceTable(); 00161 00163 enum sort_order 00164 { 00166 ORDER_ID, 00168 ORDER_NAME, 00170 ORDER_GRIDREF 00171 }; 00172 00178 row_list_ptr get_list(sort_order order = ORDER_NAME); 00179 00185 row_ptr find(int place_id); 00186 00192 row_ptr find_name(const std::string& name); 00193 00201 row_list_ptr find_gridref(const std::string& gridref); 00202 00203 }; // class PlaceTable 00204 00205 #endif // TUTORIAL_PLACES_H