builder.h
Go to the documentation of this file.
00001 // Copyright (c) 2009-2010  INRIA Sophia-Antipolis (France).
00002 // All rights reserved.
00003 //
00004 //This file is part of ESBTL.
00005 //
00006 //ESBTL is free software: you can redistribute it and/or modify
00007 //it under the terms of the GNU General Public License as published by
00008 //the Free Software Foundation, either version 3 of the License, or
00009 //(at your option) any later version.
00010 //
00011 //ESBTL is distributed in the hope that it will be useful,
00012 //but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //GNU General Public License for more details.
00015 //
00016 //You should have received a copy of the GNU General Public License
00017 //along with ESBTL.  If not, see <http://www.gnu.org/licenses/>.
00018 //
00019 //
00020 //Additional permission under GNU GPL version 3 section 7
00021 //
00022 //If you modify this Library, or any covered work, by linking or
00023 //combining it with CGAL (or a modified version of that library), the
00024 //licensors of this Library grant you additional permission to convey
00025 //the resulting work. Corresponding Source for a non-source form of
00026 //such a combination shall include the source code for the parts of CGAL
00027 //used as well as that of the covered work. 
00028 //
00029 //
00030 //
00031 // Author(s)     :  Sébastien Loriot
00032 
00033 
00034 
00035 #ifndef ESBTL_BUILDER_H
00036 #define ESBTL_BUILDER_H
00037 #include <iostream>
00038 
00039 namespace ESBTL {
00040 
00045 template<class System>
00046 class All_atom_system_builder{
00047   //TODO a selector inside the builder
00048 public:
00052   typedef std::vector <System> System_container;
00053 private:
00054   int current_model;//model_number : we expect to read one model after another
00055   System_container& systems_;
00056   bool prebuilt_systems;
00057   unsigned max_systems;
00058 public:
00059   //I think this constructor is useless
00060   //All_atom_system_builder(System_container& systems):current_model(1),systems(systems),prebuilt_systems(false),max_systems(0){}
00068   All_atom_system_builder(System_container& systems,unsigned max_systems_):
00069     current_model(1),systems_(systems),prebuilt_systems(true),max_systems(max_systems_){
00070     if (systems_.capacity()<max_systems)
00071       systems_.reserve(max_systems);
00072     //TODO warning cannot find a better method?
00073     for (unsigned i=0;i<max_systems;++i) systems_.push_back(System(i+1));
00074   }
00075   
00076 //doxygen should not read this
00078   template<class Line_format>
00079   void print_line(const Line_format& line_format,const std::string& line){
00080     std::cout << "[" << line_format.get_record_name(line) << "]" ;
00081     std::cout << "[" << line_format.get_atom_serial_number(line) << "]" ;
00082     std::cout << "[" << line_format.get_atom_name(line) << "]" ;
00083     std::cout << "[" << line_format.get_alternate_location(line) << "]" ;
00084     std::cout << "[" << line_format.get_residue_name(line) << "]" ;
00085     std::cout << "[" << line_format.get_chain_identifier(line) << "]" ;
00086     std::cout << "[" << line_format.get_residue_sequence_number(line) << "]" ;
00087     std::cout << "[" << line_format.get_insertion_code(line) << "]" ;
00088     std::cout << "[" << line_format.get_x(line) << "]" ;
00089     std::cout << "[" << line_format.get_y(line) << "]" ;
00090     std::cout << "[" << line_format.get_z(line) << "]" ;
00091     std::cout << "[" << line_format.get_occupancy(line) << "]" ;
00092     std::cout << "[" << line_format.get_temperature_factor(line) << "]" ;
00093     std::cout << "[" << line_format.get_element(line) << "]" ;
00094     std::cout << "[" << line_format.get_charge(line) << "]" ;
00095   }    
00097   
00105   template<class Line_format>
00106   void interpret_line(const Line_format& line_format,const std::string& line,int system_info){
00107     if (system_info==RMK){
00108       if (line_format.record_type()==PDB::MODEL)
00109         current_model=line_format.get_model_number(line);
00110     }
00111     else{
00112       //ensure that references remains valid. You must use the function reserve for this purpose.
00113       assert(systems_.capacity()>=(unsigned) system_info);
00114       if (!prebuilt_systems && systems_.size()<(unsigned) system_info)
00115         systems_.push_back(System(system_info));
00116       systems_[system_info-1].interpret_line(line_format,line,current_model);
00117     }
00118   }
00119 
00120   
00121   
00126   void create_systems(char altloc){
00127     for (typename System_container::iterator it=systems_.begin();it!=systems_.end();++it)
00128       it->set_altloc(altloc);
00129   }
00130   
00131 };
00132 
00133 } //namespace ESBTL
00134 
00135 #endif // ESBTL_BUILDER_H