libsequence  1.9.5
PolyTable.tcc
1 // Code for the -*- C++ -*- namespace Sequence::PolyTable template members
2 
3 /*
4 
5 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
6 
7 Remove the brackets to email me.
8 
9 This file is part of libsequence.
10 
11 libsequence is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
15 
16 libsequence is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
23 
24 */
25 
26 
27 #ifndef __POLY_TABLE_TCC__
28 #define __POLY_TABLE_TCC__
29 
30 #include <iterator>
31 
32 namespace Sequence
33 {
34  template<typename numeric_type,
35  typename string_type>
36  bool PolyTable::assign( const numeric_type * _positions,
37  const size_t & _num_positions,
38  const string_type * _data,
39  const size_t & _num_individuals )
40  {
41  //The numeric array must be convertible to double
42  static_assert( std::is_convertible<numeric_type,double>::value,
43  "numeric_type must be convertible to double");
44  //The character type must be eithe char * or std::string
45  static_assert( (std::is_same<string_type,char*>::value ||
46  std::is_same<string_type,std::string>::value),
47  "string_type must be char * or std::string");
48 
49  first.resize(_num_positions);
50  second.resize(_num_individuals);
51  first.assign(_positions,_positions+_num_positions);
52  second.assign(_data,_data+_num_individuals);
53  non_const_access = true;
54  for(std::vector<std::string>::const_iterator itr = second.begin() ;
55  itr < second.end() ; ++itr)
56  {
57  if (itr->length() != _num_positions)
58  {
59  first.clear();
60  second.clear();
61  return false;
62  }
63  }
64  return true;
65  }
66 }
67 
68 #endif