45 std::vector<KeyedAttributeTreeNewickReaderPlugin::AttributeDescriptor>
46 KeyedAttributeTreeNewickReaderPlugin::nhx_attributes_ ={
47 {
"AC", Target::kNode,
"AC",
"",
false },
48 {
"Co", Target::kNode,
"Co",
"",
false },
49 {
"D", Target::kNode,
"D",
"",
false },
50 {
"E", Target::kNode,
"E",
"",
false },
51 {
"GN", Target::kNode,
"GN",
"",
false },
52 {
"O", Target::kNode,
"O",
"",
false },
53 {
"S", Target::kNode,
"S",
"",
false },
54 {
"SO", Target::kNode,
"SO",
"",
false },
55 {
"T", Target::kNode,
"T",
"",
false },
57 {
"B", Target::kEdge,
"B",
"",
false },
58 {
"L", Target::kEdge,
"L",
"",
false },
59 {
"Sw", Target::kEdge,
"Sw",
"",
false },
69 std::string
const& key,
72 keyed_attributes_.push_back({ key, target, key,
"",
false });
77 std::string
const& source_key,
79 std::string
const& target_key
81 keyed_attributes_.push_back({ source_key, target, target_key,
"",
false });
86 std::string
const& source_key,
88 std::string
const& target_key,
89 std::string
const& default_value
91 keyed_attributes_.push_back({ source_key, target, target_key, default_value,
true });
98 catch_all_attributes_.push_back({
"", target,
"",
"",
true });
113 for(
auto const& attrib : nhx_attributes_ ) {
114 keyed_attributes_.push_back( attrib );
126 keyed_attributes_.clear();
127 catch_all_attributes_.clear();
142 auto data = get_data_( element );
146 process_keyed_attributes_( data, attributes,
Target::kNode );
147 process_catch_all_attributes_( data, attributes,
Target::kNode );
158 auto data = get_data_( element );
162 process_keyed_attributes_( data, attributes,
Target::kEdge );
163 process_catch_all_attributes_( data, attributes,
Target::kEdge );
197 bool KeyedAttributeTreeNewickReaderPlugin::has_attributes_for_target_( Target target )
const
212 for(
auto const& attrs : keyed_attributes_ ) {
213 if( attrs.target == target ) {
217 for(
auto const& attrs : catch_all_attributes_ ) {
218 if( attrs.target == target ) {
225 KeyedAttributeTreeNewickReaderPlugin::PairList KeyedAttributeTreeNewickReaderPlugin::get_data_(
226 NewickBrokerElement
const& element
228 auto result = PairList();
231 for(
auto const& comment : element.comments ) {
237 size_t pos = prefix_.size();
238 size_t last_pos = prefix_.size();
241 while( pos < comment.length() ) {
244 pos = comment.find( separator_, last_pos );
245 if( pos == std::string::npos ) {
246 pos = comment.length();
250 if( pos != last_pos ) {
252 assert( pos > last_pos );
253 auto entry = std::string( comment.data() + last_pos, pos - last_pos );
256 auto ass_pos = entry.find( assigner_ );
262 if( ass_pos != std::string::npos ) {
270 entry.substr( 0, ass_pos ),
271 entry.substr( ass_pos + 1 )
284 void KeyedAttributeTreeNewickReaderPlugin::process_keyed_attributes_(
285 PairList
const& data,
290 for(
auto const& attrs : keyed_attributes_ ) {
293 if( attrs.target != target ) {
298 bool found_key =
false;
299 for(
auto const& datum : data ) {
300 if( datum.first == attrs.source_key ) {
301 attributes[ attrs.target_key ] = datum.second;
307 if( ! found_key && attrs.use_default ) {
308 attributes[ attrs.target_key ] = attrs.default_value;
313 void KeyedAttributeTreeNewickReaderPlugin::process_catch_all_attributes_(
314 PairList
const& data,
319 for(
auto const& attrs : catch_all_attributes_ ) {
322 if( attrs.target != target ) {
327 for(
auto const& datum : data ) {
328 attributes[ datum.first ] = datum.second;