1 //	Copyright (C) 1999-2003 Paul O. Lewis
2 //
3 //	This file is part of NCL (Nexus Class Library) version 2.0.
4 //
5 //	NCL is free software; you can redistribute it and/or modify
6 //	it under the terms of the GNU General Public License as published by
7 //	the Free Software Foundation; either version 2 of the License, or
8 //	(at your option) any later version.
9 //
10 //	NCL is distributed in the hope that it will be useful,
11 //	but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 //	GNU General Public License for more details.
14 //
15 //	You should have received a copy of the GNU General Public License
16 //	along with NCL; if not, write to the Free Software Foundation, Inc.,
17 //	59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 //
19 
20 #ifndef NCL_NXSTREESBLOCK_H
21 #define NCL_NXSTREESBLOCK_H
22 
23 /*----------------------------------------------------------------------------------------------------------------------
24 |	This class handles reading and storage for the NEXUS block TREES. It overrides the member functions Read and Reset,
25 |	which are abstract virtual functions in the base class NxsBlock. The translation table (if one is supplied) is
26 |	stored in the `translateList'. The tree names are stored in `treeName' and the tree descriptions in
27 |	`treeDescription'. Information about rooting of trees is stored in `rooted'. Note that no checking is done to
28 |	ensure that the tree descriptions are valid. The validity of the tree descriptions could be checked after the TREES
29 |	block has been read (but before the next block in the file has been read) by overriding the NxsReader::ExitingBlock
30 |	member function, but no functionality for this is provided by the NCL. Below is a table showing the correspondence
31 |	between the elements of a TREES block and the variables and member functions that can be used to access each piece
32 |	of information stored.
33 |>
34 |	NEXUS command     Data members    Member functions
35 |	-----------------------------------------------------
36 |	TRANSLATE         translateList
37 |
38 |	TREE              treeName        GetTreeName
39 |	                                  GetTreeDescription
40 |	                                  GetNumTrees
41 |	                                  GetNumDefaultTree
42 |	                                  IsDefaultTree
43 |
44 |	                  rooted          IsRootedTree
45 |	-----------------------------------------------------
46 |>
47 */
48 class NxsTreesBlock
49   : public NxsBlock
50 	{
51  	public:
52 							NxsTreesBlock(NxsTaxaBlock *tb);
53 		virtual				~NxsTreesBlock();
54 
55 				void		ReplaceTaxaBlockPtr(NxsTaxaBlock *tb);
56 				unsigned	GetNumDefaultTree();
57 				unsigned	GetNumTrees();
58 				NxsString	GetTreeName(unsigned i);
59 				NxsString	GetTreeDescription(unsigned i);
60 				NxsString	GetTranslatedTreeDescription(unsigned i);
61 				bool		IsDefaultTree(unsigned i);
62 				bool		IsRootedTree(unsigned i);
63 		virtual void		Report(std::ostream &out);
64 		virtual void		BriefReport(NxsString &s);
65 		virtual void		Reset();
66 
67 	protected :
68 
69 		NxsStringMap		translateList;		/* storage for translation table (if any) */
70 		NxsStringVector		treeName;			/* storage for tree names */
71 		NxsStringVector		treeDescription;	/* storage for tree descriptions */
72 		NxsBoolVector		rooted;				/* stores information about rooting for each tree */
73 		NxsTaxaBlock		*taxa;				/* pointer to existing NxsTaxaBlock object */
74 		unsigned			ntrees;				/* number of trees stored */
75 		unsigned			defaultTree;		/* 0-offset index of default tree specified by user, or 0 if user failed to specify a default tree using an asterisk in the NEXUS data file */
76 
77 		virtual	void		Read(NxsToken &token);
78 		void				HandleTreeDescription(NxsToken &token, bool utree);
79 	};
80 
81 typedef NxsTreesBlock TreesBlock;
82 
83 #endif
84