File: modelsblock.cpp

package info (click to toggle)
iqtree 1.6.9%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 12,160 kB
  • sloc: cpp: 112,052; ansic: 53,619; python: 242; sh: 195; makefile: 52
file content (88 lines) | stat: -rw-r--r-- 2,372 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * modelsblock.cpp
 *
 *  Created on: Jan 9, 2015
 *      Author: minh
 */

#include "modelsblock.h"

ModelsBlock::ModelsBlock()  : NxsBlock(), unordered_map<string, NxsModel>()
{
	id = "MODELS";
}

ModelsBlock::~ModelsBlock() {
}

void ModelsBlock::Read(NxsToken &token)
{
	// This should be the semicolon after the block name
	token.GetNextToken();

	if (!token.Equals(";"))
		throw NxsException("Expecting ';' after MODELS block name", token);
	for (;;) {
		token.GetNextToken();
		if (token.Equals("MODEL") || token.Equals("FREQUENCY")) {
			NxsModel model;
			model.flag = (NM_FREQ * (int)token.Equals("FREQUENCY"));
			token.SetLabileFlagBit(NxsToken::preserveUnderscores);
			token.GetNextToken();
			model.name = token.GetToken();

			if (findModel(model.name)) {
				errormsg = "Duplicated model name ";
				errormsg += model.name.c_str();
				throw NxsException(errormsg, token);
			}

			token.GetNextToken();
			if (!token.Equals("="))
				throw NxsException("Expecting '=' after model name", token);

			token.SetLabileFlagBit(NxsToken::preserveUnderscores);
			token.GetNextContiguousToken(';');
			model.description = token.GetToken();

			token.GetNextToken();
			if (!token.Equals(";"))
				throw NxsException("Expecting ';' to terminate MODEL command", token);

			model.flag |= (NM_ATOMIC*(model.description.find_first_of("+*") == string::npos && model.description.find("MIX") == string::npos));

			insert({model.name, model});

		} else if (token.Equals("END") || token.Equals("ENDBLOCK")) {
			// Get the semicolon following END
			token.GetNextToken();

			if (!token.Equals(";"))
				throw NxsException("Expecting ';' to terminate the ENDBLOCK command, but found ", token);
			break;
		}	// if (token.Equals("END") || token.Equals("ENDBLOCK"))
		else {
			SkippingCommand(token.GetToken());
			do {
				token.GetNextToken();
			} while (!token.AtEOF() && !token.Equals(";"));

			if (token.AtEOF())
				throw NxsException("Unexpected end of file encountered", token);
		}	// token not END, ENDBLOCK, COST
	}
}

NxsModel *ModelsBlock::findModel(string name) {
    iterator it = find(name);
    if (it == end()) return NULL;
    return &(it->second);
}

NxsModel *ModelsBlock::findMixModel(string name) {
    NxsModel *model = findModel(name);
    if (!model) return NULL;
    if (model->flag & NM_ATOMIC)
        return NULL;
    return model;
}