[Phylobase-commits] r736 - in pkg/src: . ncl ncl.original/ncl
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Feb 8 17:47:47 CET 2010
Author: edd
Date: 2010-02-08 17:47:47 +0100 (Mon, 08 Feb 2010)
New Revision: 736
Added:
pkg/src/ncl/
pkg/src/ncl/ncl.h
pkg/src/ncl/nxsallocatematrix.h
pkg/src/ncl/nxsassumptionsblock.h
pkg/src/ncl/nxsblock.h
pkg/src/ncl/nxscdiscretematrix.h
pkg/src/ncl/nxscharactersblock.h
pkg/src/ncl/nxscxxdiscretematrix.h
pkg/src/ncl/nxsdatablock.h
pkg/src/ncl/nxsdefs.h
pkg/src/ncl/nxsdiscretedatum.h
pkg/src/ncl/nxsdistancedatum.h
pkg/src/ncl/nxsdistancesblock.h
pkg/src/ncl/nxsemptyblock.h
pkg/src/ncl/nxsexception.h
pkg/src/ncl/nxsmultiformat.h
pkg/src/ncl/nxspublicblocks.h
pkg/src/ncl/nxsreader.h
pkg/src/ncl/nxssetreader.h
pkg/src/ncl/nxsstring.h
pkg/src/ncl/nxstaxablock.h
pkg/src/ncl/nxstoken.h
pkg/src/ncl/nxstreesblock.h
pkg/src/ncl/nxsunalignedblock.h
pkg/src/ncl/nxsutilcopy.h
pkg/src/nxsassumptionsblock.cpp
pkg/src/nxsblock.cpp
pkg/src/nxscharactersblock.cpp
pkg/src/nxscxxdiscretematrix.cpp
pkg/src/nxsdatablock.cpp
pkg/src/nxsdistancedatum.cpp
pkg/src/nxsdistancesblock.cpp
pkg/src/nxsemptyblock.cpp
pkg/src/nxsexception.cpp
pkg/src/nxsmultiformat.cpp
pkg/src/nxspublicblocks.cpp
pkg/src/nxsreader.cpp
pkg/src/nxssetreader.cpp
pkg/src/nxsstring.cpp
pkg/src/nxstaxablock.cpp
pkg/src/nxstoken.cpp
pkg/src/nxstreesblock.cpp
pkg/src/nxsunalignedblock.cpp
Removed:
pkg/src/ncl.original/ncl/ncl.h
pkg/src/ncl.original/ncl/nxsallocatematrix.h
pkg/src/ncl.original/ncl/nxsassumptionsblock.cpp
pkg/src/ncl.original/ncl/nxsassumptionsblock.h
pkg/src/ncl.original/ncl/nxsblock.cpp
pkg/src/ncl.original/ncl/nxsblock.h
pkg/src/ncl.original/ncl/nxscdiscretematrix.h
pkg/src/ncl.original/ncl/nxscharactersblock.cpp
pkg/src/ncl.original/ncl/nxscharactersblock.h
pkg/src/ncl.original/ncl/nxscxxdiscretematrix.cpp
pkg/src/ncl.original/ncl/nxscxxdiscretematrix.h
pkg/src/ncl.original/ncl/nxsdatablock.cpp
pkg/src/ncl.original/ncl/nxsdatablock.h
pkg/src/ncl.original/ncl/nxsdefs.h
pkg/src/ncl.original/ncl/nxsdiscretedatum.h
pkg/src/ncl.original/ncl/nxsdistancedatum.cpp
pkg/src/ncl.original/ncl/nxsdistancedatum.h
pkg/src/ncl.original/ncl/nxsdistancesblock.cpp
pkg/src/ncl.original/ncl/nxsdistancesblock.h
pkg/src/ncl.original/ncl/nxsemptyblock.cpp
pkg/src/ncl.original/ncl/nxsemptyblock.h
pkg/src/ncl.original/ncl/nxsexception.cpp
pkg/src/ncl.original/ncl/nxsexception.h
pkg/src/ncl.original/ncl/nxsmultiformat.cpp
pkg/src/ncl.original/ncl/nxsmultiformat.h
pkg/src/ncl.original/ncl/nxspublicblocks.cpp
pkg/src/ncl.original/ncl/nxspublicblocks.h
pkg/src/ncl.original/ncl/nxsreader.cpp
pkg/src/ncl.original/ncl/nxsreader.h
pkg/src/ncl.original/ncl/nxssetreader.cpp
pkg/src/ncl.original/ncl/nxssetreader.h
pkg/src/ncl.original/ncl/nxsstring.cpp
pkg/src/ncl.original/ncl/nxsstring.h
pkg/src/ncl.original/ncl/nxstaxablock.cpp
pkg/src/ncl.original/ncl/nxstaxablock.h
pkg/src/ncl.original/ncl/nxstoken.cpp
pkg/src/ncl.original/ncl/nxstoken.h
pkg/src/ncl.original/ncl/nxstreesblock.cpp
pkg/src/ncl.original/ncl/nxstreesblock.h
pkg/src/ncl.original/ncl/nxsunalignedblock.cpp
pkg/src/ncl.original/ncl/nxsunalignedblock.h
pkg/src/ncl.original/ncl/nxsutilcopy.h
Log:
new layout for NCL files permitting direct build
Copied: pkg/src/ncl/ncl.h (from rev 735, pkg/src/ncl.original/ncl/ncl.h)
===================================================================
--- pkg/src/ncl/ncl.h (rev 0)
+++ pkg/src/ncl/ncl.h 2010-02-08 16:47:47 UTC (rev 736)
@@ -0,0 +1,108 @@
+// Copyright (C) 1999-2003 Paul O. Lewis
+//
+// This file is part of NCL (Nexus Class Library) version 2.0.
+//
+// NCL is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// NCL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with NCL; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+
+#ifndef NCL_NCL_H
+#define NCL_NCL_H
+
+#if defined(_MSC_VER)
+# pragma warning(disable:4786)
+# pragma warning(disable:4291)
+# if _MSC_VER >= 1500
+# include <cstdio>
+# if !defined(vsnprintf)
+# define vsnprintf _vsnprintf_s
+# endif
+# define sprintf sprintf_s
+# else
+# define vsnprintf _vsnprintf
+# endif
+#endif
+
+#if !defined(__DECCXX)
+# include <cctype>
+# include <cmath>
+# include <cstdarg>
+# include <cstdio>
+# include <cstdarg>
+# include <cstdlib>
+# include <ctime>
+# include <climits>
+# include <cfloat>
+#else
+# include <ctype.h>
+# include <stdarg.h>
+# include <math.h>
+# include <stdarg.h>
+# include <stdio.h>
+# include <stdlib.h>
+# include <time.h>
+# include <float.h>
+#endif
+
+#include <algorithm>
+#include <fstream>
+#include <iomanip>
+#include <iostream>
+#include <list>
+#include <map>
+#include <set>
+#include <stdexcept>
+#include <string>
+#if defined(__GNUC__)
+# if __GNUC__ < 3
+# include <strstream>
+# else
+# include <sstream>
+# endif
+#endif
+#include <vector>
+using namespace std;
+
+#if defined( __BORLANDC__ )
+# include <dos.h>
+#endif
+
+#if defined(__MWERKS__)
+# define HAVE_PRAGMA_UNUSED
+ // mwerks (and may be other compilers) want return values even if the function throws an exception
+ //
+# define DEMANDS_UNREACHABLE_RETURN
+
+#endif
+
+#include "ncl/nxsdefs.h"
+#include "ncl/nxsstring.h"
+#include "ncl/nxsexception.h"
+#include "ncl/nxstoken.h"
+#include "ncl/nxsblock.h"
+#include "ncl/nxsreader.h"
+#include "ncl/nxssetreader.h"
+#include "ncl/nxstaxablock.h"
+#include "ncl/nxstreesblock.h"
+#include "ncl/nxsdistancedatum.h"
+#include "ncl/nxsdistancesblock.h"
+#include "ncl/nxsdiscretedatum.h"
+#include "ncl/nxscharactersblock.h"
+#include "ncl/nxsassumptionsblock.h"
+#include "ncl/nxsdatablock.h"
+#include "ncl/nxsunalignedblock.h"
+#include "ncl/nxspublicblocks.h"
+#include "ncl/nxsmultiformat.h"
+
+#endif
Copied: pkg/src/ncl/nxsallocatematrix.h (from rev 735, pkg/src/ncl.original/ncl/nxsallocatematrix.h)
===================================================================
--- pkg/src/ncl/nxsallocatematrix.h (rev 0)
+++ pkg/src/ncl/nxsallocatematrix.h 2010-02-08 16:47:47 UTC (rev 736)
@@ -0,0 +1,205 @@
+// Copyright (C) 2008 Mark Holder
+//
+// This file is part of NCL (Nexus Class Library) version 2.1
+//
+// NCL is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// NCL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with NCL; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+// This code is based on code developed by Mark Holder for the CIPRES project
+
+#if !defined (NXS_ALLOCATE_MATRIX_H)
+# define NXS_ALLOCATE_MATRIX_H
+
+#include "ncl/nxsdefs.h"
+
+template<typename T>
+T *** NewThreeDArray(unsigned f , unsigned s , unsigned t);
+template<typename T>
+T ** NewTwoDArray(unsigned f , unsigned s);
+template<typename T>
+void DeleteThreeDArray(T ***& ptr);
+template<typename T>
+void DeleteTwoDArray(T **& ptr);
+
+/*--------------------------------------------------------------------------------------------------------------------------
+| Allocates a three dimensional array of doubles as one contiguous block of memory
+| the dimensions are f two dimensional arrays that are s by t.
+| the array is set up so that
+| for(i = 0 ; i < f ; i++)
+| for (j = 0 ; j < s ; j++)
+| for (k = 0 ; k < t; k++)
+| array[i][j][k];
+|
+| would be the same order of access as:
+|
+| T *ptr = **array;
+| for (i = 0 ; i < f*s*t ; i++)
+| *ptr++;
+*/
+template<typename T> T *** NewThreeDArray(unsigned f , unsigned s , unsigned t)
+ {
+ NCL_ASSERT(f > 0 && s > 0 && t> 0);
+ const unsigned twoDStride = s*t;
+ T ***ptr;
+ ptr = new T **[f];
+ ptr[0] = new T *[f * s];
+ ptr[0][0] = new T[f * s * t];
+ for (unsigned sIt = 1 ; sIt < s ; sIt++)
+ ptr[0][sIt] = ptr[0][sIt-1] + t ;
+ for (unsigned fIt = 1 ; fIt < f ; fIt ++)
+ {
+ ptr[fIt] = ptr[fIt -1] + s ;
+ ptr[fIt][0] = ptr[fIt -1][0] + twoDStride;
+ for (unsigned sIt = 1 ; sIt < s ; sIt++)
+ ptr[fIt][sIt] = ptr[fIt][sIt-1] + t ;
+ }
+ return ptr;
+ }
+
+/*--------------------------------------------------------------------------------------------------------------------------
+| Delete a Three Dimensional Array that has been allocated using NewThreeDArray and sets the pointer to NULL
+*/
+template<typename T> void DeleteThreeDArray (T *** & ptr)
+ {
+ if (ptr)
+ {
+ if (*ptr)
+ {
+ delete [] **ptr;
+ delete [] * ptr;
+ }
+ delete [] ptr;
+ }
+ ptr = NULL;
+ }
+
+/*--------------------------------------------------------------------------------------------------------------------------
+| Allocates a two dimensional array of doubles as one contiguous block of memory
+| the dimensions are f by s.
+| the array is set up so that
+|
+| for(i = 0 ; i < f ; i++)
+| for (j = 0 ; j < s ; j++)
+| array[i][j];
+|
+| would be the same order of access as:
+|
+| T *ptr = **array;
+| for (i = 0 ; i < f*s*t ; i++)
+| *ptr++;
+*/
+template<typename T> T **NewTwoDArray(unsigned f , unsigned s)
+ {
+ NCL_ASSERT(f > 0 && s > 0);
+ T **ptr;
+ ptr = new T *[f];
+ *ptr = new T [f * s];
+ for (unsigned fIt = 1 ; fIt < f ; fIt ++)
+ ptr[fIt] = ptr[fIt -1] + s ;
+ return ptr;
+ }
+
+/*--------------------------------------------------------------------------------------------------------------------------
+| Delete a 2 Dimensional Array NewTwoDArray and set the ptr to NULL
+*/
+template<typename T> inline void DeleteTwoDArray (T ** & ptr)
+ {
+ if (ptr)
+ {
+ delete [] * ptr;
+ delete [] ptr;
+ ptr = NULL;
+ }
+ }
+
+template<typename T>
+class ScopedThreeDMatrix
+ {
+ public:
+ T *** ptr;
+
+ T *** GetAlias() const
+ {
+ return ptr;
+ }
+ ScopedThreeDMatrix(unsigned f = 0, unsigned s = 0, unsigned t = 0)
+ :ptr(NULL)
+ {
+ Initialize(f, s, t);
+ }
+ void Initialize(unsigned f = 0, unsigned s = 0, unsigned t = 0)
+ {
+ if (f > 0 && s > 0 && t > 0)
+ ptr = NewThreeDArray<T>(f, s, t);
+ else
+ DeleteThreeDArray<T>(ptr);
+ }
+ T ***Surrender()
+ {
+ T ***temp = ptr;
+ ptr = NULL;
+ return temp;
+ }
+ ~ScopedThreeDMatrix()
+ {
+ //POL-23Dec2008 was "if (!ptr)", which obviously caused a memory leak
+ if (ptr)
+ DeleteThreeDArray<T>(ptr);
+ }
+ };
+
+
+template<typename T>
+class ScopedTwoDMatrix
+ {
+
+ public:
+ T ** ptr;
+
+ T ** GetAlias() const
+ {
+ return ptr;
+ }
+ ScopedTwoDMatrix(unsigned f = 0, unsigned s = 0)
+ :ptr(NULL)
+ {
+ Initialize(f, s);
+ }
+ void Initialize(unsigned f, unsigned s)
+ {
+ if (f > 0 && s > 0)
+ ptr = NewTwoDArray<T>(f, s);
+ else
+ DeleteTwoDArray<T>(ptr);
+ }
+ T **Surrender()
+ {
+ T** temp = ptr;
+ ptr = NULL;
+ return temp;
+ }
+ ~ScopedTwoDMatrix()
+ {
+ if (ptr != NULL)
+ DeleteTwoDArray<T>(ptr);
+ }
+ };
+
+typedef ScopedTwoDMatrix<double> ScopedDblTwoDMatrix;
+typedef ScopedTwoDMatrix<unsigned> ScopedUIntTwoDMatrix;
+
+typedef ScopedThreeDMatrix<double> ScopedDblThreeDMatrix;
+typedef ScopedThreeDMatrix<unsigned> ScopedUIntThreeDMatrix;
+
+#endif
Copied: pkg/src/ncl/nxsassumptionsblock.h (from rev 735, pkg/src/ncl.original/ncl/nxsassumptionsblock.h)
===================================================================
--- pkg/src/ncl/nxsassumptionsblock.h (rev 0)
+++ pkg/src/ncl/nxsassumptionsblock.h 2010-02-08 16:47:47 UTC (rev 736)
@@ -0,0 +1,361 @@
+// Copyright (C) 1999-2003 Paul O. Lewis
+//
+// This file is part of NCL (Nexus Class Library) version 2.0.
+//
+// NCL is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// NCL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with NCL; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+
+#ifndef NCL_ASSUMPTIONSBLOCK_H
+#define NCL_ASSUMPTIONSBLOCK_H
+
+#include <vector>
+
+#include "ncl/nxsdefs.h"
+#include "ncl/nxsblock.h"
+#include "ncl/nxstreesblock.h"
+#include "ncl/nxscharactersblock.h"
+#include "ncl/nxstaxablock.h"
+
+class NxsCharactersBlockAPI;
+class NxsTaxaBlockAPI;
+
+using std::vector;
+
+class NxsAssumptionsBlockAPI
+ : public NxsBlock
+ {
+ public:
+ virtual void SetCallback(NxsCharactersBlockAPI *p) = 0;
+
+
+
+ virtual void SetCharBlockPtr(NxsCharactersBlockAPI * c, NxsBlockLinkStatus s) = 0;
+ virtual void SetTaxaBlockPtr(NxsTaxaBlockAPI *, NxsBlockLinkStatus s) = 0;
+ virtual void SetTreesBlockPtr(NxsTreesBlockAPI *, NxsBlockLinkStatus s) = 0;
+
+ virtual NxsCharactersBlockAPI * GetCharBlockPtr(int *status=NULL) = 0;
+ virtual NxsTaxaBlockAPI * GetTaxaBlockPtr(int *status=NULL) = 0;
+ virtual NxsTreesBlockAPI * GetTreesBlockPtr(int *status=NULL) = 0;
+
+ virtual void AddCharPartition(const std::string & name, const NxsPartition &) = 0;
+ virtual void AddTaxPartition(const std::string & name, const NxsPartition &) = 0;
+ virtual void AddTreePartition(const std::string & name, const NxsPartition &) = 0;
+ virtual void AddCodeSet(const std::string & name, const NxsPartition &, bool asterisked) = 0;
+ virtual void AddCodonPosSet(const std::string & name, const NxsPartition &, bool asterisked) = 0;
+
+ virtual void FlagCharBlockAsUsed() = 0;
+ virtual void FlagTaxaBlockAsUsed() = 0;
+ virtual void FlagTreesBlockAsUsed() = 0;
+
+ virtual void ReadCharsetDef(NxsString charset_name, NxsToken &token, bool asterisked) = 0;
+ virtual void ReadExsetDef(NxsString charset_name, NxsToken &token, bool asterisked) = 0;
+ virtual void ReadTaxsetDef(NxsString set_name, NxsToken &token, bool asterisked) = 0;
+ virtual void ReadTreesetDef(NxsString set_name, NxsToken &token, bool asterisked) = 0;
+
+ virtual NxsTransformationManager & GetNxsTransformationManagerRef() = 0;
+ virtual NxsGeneticCodesManager & GetNxsGeneticCodesManagerRef() = 0;
+ virtual void SetGapsAsNewstate(bool v) = 0;
+ };
+
+/*----------------------------------------------------------------------------------------------------------------------
+| This class handles reading and storage for the NxsReader block ASSUMPTIONS. It overrides the member functions Read
+| and Reset, which are abstract virtual functions in the base class NxsBlock. Adding a new data member? Don't forget
+| to:
+|~
+| o Describe it in the class declaration using a C-style comment.
+| o Initialize it (unless it is self-initializing) in the constructor and re-initialize it in the Reset function.
+| o Describe the initial state in the constructor documentation.
+| o Delete memory allocated to it in both the destructor and Reset function.
+| o Report it in some way in the Report function.
+|~
+*/
+class NxsAssumptionsBlock
+ : public NxsAssumptionsBlockAPI
+ {
+ enum NameOfAssumpBlockAsRead
+ {
+ UNREAD_OR_GENERATED_BLOCK,
+ ASSUMPTIONS_BLOCK_READ,
+ SETS_BLOCK_READ,
+ CODONS_BLOCK_READ
+ };
+
+
+ public:
+ NxsAssumptionsBlock(NxsTaxaBlockAPI *t);
+ virtual ~NxsAssumptionsBlock();
+
+ virtual bool CanReadBlockType(const NxsToken & token);
+
+ void ReplaceTaxaBlockPtr(NxsTaxaBlockAPI *tb);
+ void SetCallback(NxsCharactersBlockAPI *p);
+
+ int GetNumCharSets() const;
+ void GetCharSetNames(NxsStringVector &names) const;
+ const NxsUnsignedSet *GetCharSet(NxsString nm) const;
+
+ int GetNumCharPartitions();
+ void GetCharPartitionNames(vector<std::string> &names);
+ const NxsPartition *GetCharPartition(std::string nm) const;
+
+ int GetNumTaxSets();
+ void GetTaxSetNames(NxsStringVector &names);
+ NxsUnsignedSet &GetTaxSet(NxsString nm);
+
+ int GetNumExSets();
+ void GetExSetNames(NxsStringVector &names);
+ NxsUnsignedSet &GetExSet(NxsString nm);
+ NxsString GetDefExSetName();
+ void ApplyExset(NxsString nm);
+
+ virtual void Read(NxsToken& token);
+ virtual void Report(std::ostream& out) NCL_COULD_BE_CONST ;
+ virtual void Reset();
+ virtual void WriteAsNexus(std::ostream &out) const;
+
+ /*only used it the linkAPI is enabled*/
+ virtual void HandleLinkCommand(NxsToken & );
+ virtual void WriteLinkCommand(std::ostream &out) const;
+
+ virtual VecBlockPtr GetImpliedBlocks()
+ {
+ return GetCreatedTaxaBlocks();
+ }
+
+ int GetCharLinkStatus() {return charLinkStatus;}
+ int GetTaxaLinkStatus() {return taxaLinkStatus;}
+ int GetTreesLinkStatus() {return treesLinkStatus;}
+
+ void FlagCharBlockAsUsed() {charLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
+ void FlagTaxaBlockAsUsed() {taxaLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
+ void FlagTreesBlockAsUsed() {treesLinkStatus |= NxsBlock::BLOCK_LINK_USED;}
+
+ void SetCharLinkStatus(NxsBlockLinkStatus s);
+ void SetTaxaLinkStatus(NxsBlockLinkStatus s);
+ void SetTreesLinkStatus(NxsBlockLinkStatus s);
+
+ void SetCharBlockPtr(NxsCharactersBlockAPI * c, NxsBlockLinkStatus s);
+ void SetTaxaBlockPtr(NxsTaxaBlockAPI *, NxsBlockLinkStatus s);
+ void SetTreesBlockPtr(NxsTreesBlockAPI *, NxsBlockLinkStatus s);
+ NxsCharactersBlockAPI * GetCharBlockPtr(int *status=NULL);
+ NxsTaxaBlockAPI * GetTaxaBlockPtr(int *status=NULL);
+ NxsTreesBlockAPI * GetTreesBlockPtr(int *status=NULL);
+
+ NxsTransformationManager & GetNxsTransformationManagerRef()
+ {
+ return transfMgr;
+ }
+ NxsGeneticCodesManager & GetNxsGeneticCodesManagerRef()
+ {
+ return codesMgr;
+ }
+ virtual void AddCharPartition(const std::string & name, const NxsPartition &);
+ virtual void AddTaxPartition(const std::string & name, const NxsPartition &);
+ virtual void AddTreePartition(const std::string & name, const NxsPartition &);
+ virtual void AddCodeSet(const std::string & name, const NxsPartition &, bool asterisked);
+ virtual void AddCodonPosSet(const std::string & name, const NxsPartition &, bool asterisked);
+
+ /*---------------------------------------------------------------------------------------
+ | Results in aliasing of the taxa, trees, and characters blocks!
+ */
+ NxsAssumptionsBlock &operator=(const NxsAssumptionsBlock &other)
+ {
+ CopyBaseBlockContents(static_cast<const NxsBlock &>(other));
+ CopyAssumptionsContents(other);
+ return *this;
+ }
+
+ /*---------------------------------------------------------------------------------------
+ | Results in aliasing of the taxa, trees, and characters blocks!
+ |
+ | passedRefOfOwnedBlock is set to this->true to avoid double deletion (other
+ | retains ownership of these blocks
+ */
+ virtual void CopyAssumptionsContents(const NxsAssumptionsBlock &other)
+ {
+ taxa = other.taxa;
+ charBlockPtr = other.charBlockPtr;
+ treesBlockPtr = other.treesBlockPtr;
+ charsets = other.charsets;
+ taxsets = other.taxsets;
+ treesets = other.treesets;
+ exsets = other.exsets;
+ charPartitions = other.charPartitions;
+ taxPartitions = other.taxPartitions;
+ treePartitions = other.treePartitions;
+ def_exset = other.def_exset;
+ charLinkStatus = other.charLinkStatus;
+ taxaLinkStatus = other.taxaLinkStatus;
+ treesLinkStatus = other.treesLinkStatus;
+ passedRefOfOwnedBlock = true;
+ readAs = other.readAs;
+ transfMgr = other.transfMgr;
+ codesMgr = other.codesMgr;
+ createdSubBlocks = other.createdSubBlocks;
+ polyTCountValue = other.polyTCountValue;
+ gapsAsNewstate = other.gapsAsNewstate;
+ codonPosSets = other.codonPosSets;
+ def_codonPosSet = other.def_codonPosSet;
+ codeSets = other.codeSets;
+ def_codeSet = other.def_codeSet;
+ }
+
+ virtual NxsAssumptionsBlock * Clone() const
+ {
+ NxsAssumptionsBlock * a = new NxsAssumptionsBlock(taxa);
+ *a = *this;
+ return a;
+ }
+ virtual void SetGapsAsNewstate(bool v)
+ {
+ gapsAsNewstate = v;
+ }
+
+
+ protected:
+ typedef std::vector<NxsAssumptionsBlockAPI *> VecAssumpBlockPtr;
+
+ virtual void ReadCharsetDef(NxsString charset_name, NxsToken &token, bool asterisked);
+ virtual void ReadExsetDef(NxsString charset_name, NxsToken &token, bool asterisked);
+ virtual void ReadTreesetDef(NxsString set_name, NxsToken &token, bool asterisked);
+ virtual void ReadTaxsetDef(NxsString set_name, NxsToken &token, bool asterisked);
+
+
+ VecBlockPtr GetCreatedTaxaBlocks();
+ virtual unsigned TaxonLabelToNumber(NxsString s) const;
+
+ void HandleCharPartition(NxsToken& token);
+ void HandleCharSet(NxsToken& token);
+ void HandleCodeSet(NxsToken& token);
+ void HandleCodonPosSet(NxsToken& token);
+ void HandleExSet(NxsToken& token);
+ void HandleOptions(NxsToken & token);
+ void HandleTaxPartition(NxsToken& token);
+ void HandleTaxSet(NxsToken& token);
+ void HandleTreePartition(NxsToken& token);
+ void HandleTreeSet(NxsToken& token);
+ void HandleTypeSet(NxsToken& token);
+ void HandleUserType(NxsToken& token);
+ void HandleWeightSet(NxsToken& token);
+
+ void WriteCharSet(std::ostream &out) const
+ {
+ NxsWriteSetCommand("CHARSET", charsets, out);
+ }
+ void WriteCharPartition(std::ostream &out) const
+ {
+ NxsWritePartitionCommand("CharPartition", charPartitions, out);
+ }
+ void WriteExSet(std::ostream &out) const
+ {
+ NxsWriteSetCommand("EXSET", exsets, out, def_exset.c_str());
+ }
+ void WriteOptions(std::ostream &out) const;
+ void WriteTaxPartition(std::ostream &out) const
+ {
+ NxsWritePartitionCommand("TaxPartition", taxPartitions, out);
+ }
+ void WriteTaxSet(std::ostream &out) const
+ {
+ NxsWriteSetCommand("TAXSET", taxsets, out);
+ }
+ void WriteTreePartition(std::ostream &out) const
+ {
+ NxsWritePartitionCommand("TreePartition", treePartitions, out);
+ }
+ void WriteTreeSet(std::ostream &out) const
+ {
+ NxsWriteSetCommand("TREESET", treesets, out);
+ }
+ void WriteCodeSet(std::ostream &out) const
+ {
+ NxsWritePartitionCommand("CodeSet", codeSets, out, def_codeSet.c_str());
+ }
+ void WriteCodonPosSet(std::ostream &out) const
+ {
+ NxsWritePartitionCommand("CodonPosSet", codonPosSets, out, def_codonPosSet.c_str());
+ }
+
+ private:
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForCharTitle(const char *title, NxsToken &token, const char *cmd);
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForTaxaTitle(const char *title, NxsToken &token, const char *cmd);
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForTreesTitle(const char *title, NxsToken &token, const char *cmd);
+
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForCharBlock(NxsCharactersBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForTaxaBlock(NxsTaxaBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
+ NxsAssumptionsBlockAPI *GetAssumptionsBlockForTreesBlock(NxsTreesBlockAPI *, NxsBlockLinkStatus, NxsToken &token);
+
+ NxsAssumptionsBlockAPI *CreateNewAssumptionsBlock(NxsToken &token);
+ NxsAssumptionsBlockAPI *DealWithPossibleParensInCharDependentCmd(NxsToken &token, const char *cmd, const std::vector<std::string> *unsupported = NULL, bool * isVect = false);
+ bool HasAssumptionsBlockCommands() const;
+ bool HasSetsBlockCommands() const;
+ bool HasCodonsBlockCommands() const;
+
+
+ NxsTaxaBlockAPI *taxa; /* pointer to the NxsTaxaBlockAPI object */
+ NxsCharactersBlockAPI *charBlockPtr; /* pointer to the NxsCharactersBlockAPI-derived object to be notified in the event of exset changes */
+ NxsTreesBlockAPI *treesBlockPtr; /* pointer to the NxsTreesBlockAPI-derived object to be notified in the event of exset changes */
+
+
+
+ NxsUnsignedSetMap charsets;
+ NxsUnsignedSetMap taxsets;
+ NxsUnsignedSetMap treesets;
+ NxsUnsignedSetMap exsets;
+
+ NxsPartitionsByName charPartitions;
+ NxsPartitionsByName taxPartitions;
+ NxsPartitionsByName treePartitions;
+
+ NxsString def_exset; /* the default exset */
+
+ NxsPartitionsByName codonPosSets;
+ NxsString def_codonPosSet; /* the default codonPosSet */
+ NxsPartitionsByName codeSets;
+ NxsString def_codeSet; /* the default codeSet */
+
+ int charLinkStatus;
+ int taxaLinkStatus;
+ int treesLinkStatus;
+ bool passedRefOfOwnedBlock;
+ NameOfAssumpBlockAsRead readAs;
+ NxsTransformationManager transfMgr;
+ NxsGeneticCodesManager codesMgr;
+
+ std::vector<NxsAssumptionsBlockAPI *> createdSubBlocks;
+ enum PolyTCountValue
+ {
+ POLY_T_COUNT_UNKNOWN,
+ POLY_T_COUNT_MIN,
+ POLY_T_COUNT_MAX
+ };
+ PolyTCountValue polyTCountValue;
+ bool gapsAsNewstate;
+
+ friend class NxsAssumptionsBlockFactory;
+ friend class PublicNexusReader;
+ };
+
+class NxsAssumptionsBlockFactory
+ :public NxsBlockFactory
+ {
+ public:
+ virtual NxsAssumptionsBlock * GetBlockReaderForID(const std::string & id, NxsReader *reader, NxsToken *token);
+ };
+
+typedef NxsAssumptionsBlock AssumptionsBlock; // for backward compatibility
+
+#endif
+
Copied: pkg/src/ncl/nxsblock.h (from rev 735, pkg/src/ncl.original/ncl/nxsblock.h)
===================================================================
--- pkg/src/ncl/nxsblock.h (rev 0)
+++ pkg/src/ncl/nxsblock.h 2010-02-08 16:47:47 UTC (rev 736)
@@ -0,0 +1,294 @@
+// Copyright (C) 1999-2003 Paul O. Lewis
+//
+// This file is part of NCL (Nexus Class Library) version 2.0.
+//
+// NCL is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// NCL is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with NCL; if not, write to the Free Software Foundation, Inc.,
+// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+#ifndef NCL_NXSBLOCK_H
+#define NCL_NXSBLOCK_H
+
+#include <vector>
+#include "ncl/nxsdefs.h"
+#include "ncl/nxsexception.h"
+#include "ncl/nxstoken.h"
+
+class NxsReader;
+class NxsBlock;
+class NxsTaxaBlockAPI;
+
+typedef std::vector<NxsBlock *> VecBlockPtr;
+typedef std::vector<const NxsBlock *> VecConstBlockPtr;
+typedef std::pair<const NxsBlock *, std::string> BlockUniqueID;
+typedef std::map<BlockUniqueID, NxsBlock *> NxsBlockMapper;
+
+class NxsLabelToIndicesMapper
+ {
+ public:
+ virtual ~NxsLabelToIndicesMapper(){}
+ virtual unsigned GetMaxIndex() const = 0;
+ virtual unsigned GetIndicesForLabel(const std::string &label, NxsUnsignedSet *inds) const = 0;
+ /* Returns true if the set replaces an old set*/
+ virtual unsigned GetIndexSet(const std::string &label, NxsUnsignedSet * toFill) const = 0;
+ virtual bool AddNewIndexSet(const std::string &label, const NxsUnsignedSet & inds) = 0;
+ virtual bool AddNewPartition(const std::string &label, const NxsPartition & inds) = 0;
+
+ /// AppendNewLabel is only overloaded in Taxa and State LabelToIndexMappers
+ virtual unsigned AppendNewLabel(std::string &/*label*/)
+ {
+ throw NxsUnimplementedException("AppendNewLabel called on fixed label interface");
+ }
+ protected:
+ static unsigned GetIndicesFromSets(const std::string &label, NxsUnsignedSet *inds, const NxsUnsignedSetMap & itemSets);
+ static unsigned GetIndicesFromSetOrAsNumber(const std::string &label, NxsUnsignedSet *inds, const NxsUnsignedSetMap & itemSets, const unsigned maxInd, const char * itemType);
+ };
+
+class NxsSetVectorItemValidator;
+
+std::string GetBlockIDTitleString(NxsBlock &);
+/*----------------------------------------------------------------------------------------------------------------------
+| This is the base class from which all block classes are derived. A NxsBlock-derived class encapsulates a Nexus block
+| (e.g. DATA block, TREES block, etc.). The abstract virtual function Read must be overridden for each derived class
+| to provide the ability to read everything following the block name (which is read by the NxsReader object) to the
+| end or endblock statement. Derived classes must provide their own data storage and access functions. The abstract
+| virtual function Report must be overridden to provide some feedback to user on contents of block. The abstract
+| virtual function Reset must be overridden to empty the block of all its contents, restoring it to its
+| just-constructed state.
+*/
+class NxsBlock
+ {
+ friend class NxsReader;
+
+ public:
+ enum NxsBlockLinkStatus
+ {
+ BLOCK_LINK_UNINITIALIZED = 0x00,
+ BLOCK_LINK_UNKNOWN_STATUS = 0x01, /*backwards compatibility, this is the status of old block links*/
+ BLOCK_LINK_TO_ONLY_CHOICE = 0x02,
+ BLOCK_LINK_TO_MOST_RECENT = 0x04,
+ BLOCK_LINK_TO_IMPLIED_BLOCK = 0x08,
+ BLOCK_LINK_FROM_LINK_CMD = 0x10,
+ BLOCK_LINK_EQUIVALENT_TO_IMPLIED = 0x20,
+ BLOCK_LINK_UNUSED_MASK = 0x3F,
+ BLOCK_LINK_USED = 0x40
+ };
+ enum NxsCommandResult
+ {
+ STOP_PARSING_BLOCK,
+ HANDLED_COMMAND,
+ UNKNOWN_COMMAND
+ };
+ NxsBlock();
+ virtual ~NxsBlock();
+
+ virtual void SetNexus(NxsReader *nxsptr);
+ NxsReader *GetNexus() const;
+ virtual bool CanReadBlockType(const NxsToken & token)
+ {
+ return token.Equals(id);
+ }
+
+ NxsString GetID() const;
+ bool IsEmpty() NCL_COULD_BE_CONST ;
+
+ void Enable();
+ void Disable();
+ bool IsEnabled() NCL_COULD_BE_CONST ;
+ bool IsUserSupplied() NCL_COULD_BE_CONST ;
+
+ virtual unsigned CharLabelToNumber(NxsString s) NCL_COULD_BE_CONST ;
+ virtual unsigned TaxonLabelToNumber(NxsString s) const;
+
+ virtual void SkippingCommand(NxsString commandName);
+
+ virtual void HandleBlockIDCommand(NxsToken &token);
+ virtual void HandleEndblock(NxsToken &token);
+ virtual void HandleLinkCommand(NxsToken &token);
+ virtual void HandleTitleCommand(NxsToken &token);
+
+ virtual void Report(std::ostream &out) NCL_COULD_BE_CONST ;
+ virtual void Reset();
+
+ mutable NxsString errormsg; /* workspace for creating error messages */
+
+
+ virtual VecBlockPtr GetImpliedBlocks();
+ virtual VecConstBlockPtr GetImpliedBlocksConst() const;
+ BlockUniqueID GetInstanceIdentifier() const
+ {
+ return BlockUniqueID(this, GetInstanceName());
+ }
+
+ const std::string &GetInstanceName() const
+ {
+ return title;
+ }
+ virtual NxsBlock *CloneBlock(NxsBlockMapper &memo) const;
+ bool ImplementsLinkAPI() const;
+ void SetImplementsLinkAPI(bool v);
+
+ virtual void WriteAsNexus(std::ostream &out) const;
+ virtual void WriteBlockIDCommand(std::ostream &out) const;
+ virtual void WriteLinkCommand(std::ostream &out) const;
+ virtual void WriteTitleCommand(std::ostream &out) const;
+ std::string GetTitle() const
+ {
+ return title;
+ }
+ void SetTitle(const std::string &t, bool autogeneratedTitle)
+ {
+ title = t;
+ autoTitle = autogeneratedTitle;
+ }
+ bool IsAutoGeneratedTitle() const
+ {
+ return autoTitle;
+ }
+ void StoreSkippedCommands(bool v)
+ {
+ storeSkippedCommands = v;
+ }
+ void ClearStoredSkippedCommands()
+ {
+ skippedCommands.clear();
+ }
+
+ /*----------------------------------------------------------------------------------------
+ | Copies all NxsBlock fields - execept the `nexusReader` and `next` pointers.
+ | Aliasing of Block pointers results in very dangerous implication of copying for
+ | many subclasses of NxsBlock.
+ | Copying of blocks should be restricted to empty blocks without linkages (e.g.
+ | the CloneFactory mechanism requires some form of copy, but should typically be used with
+ | empty blocks.
+ */
+
+ virtual void CopyBaseBlockContents(const NxsBlock &other)
+ {
+ errormsg = other.errormsg;
+ isEmpty = other.isEmpty;
+ isEnabled = other.isEnabled;
+ isUserSupplied = other.isUserSupplied;
+ id = other.id;
+ title = other.title;
+ blockIDString = other.blockIDString;
+ linkAPI = other.linkAPI;
+ storeSkippedCommands = other.storeSkippedCommands;
+ skippedCommands = other.skippedCommands;
+ autoTitle = other.autoTitle;
+ }
+
+ virtual NxsBlock * Clone() const
+ {
+ NxsBlock * b = new NxsBlock();
+ b->CopyBaseBlockContents(*this);
+ b->nexusReader = NULL;
+ b->next = NULL;
+ return b;
+ }
+
+ unsigned ReadVectorPartitionDef(NxsPartition &np, NxsLabelToIndicesMapper <m, const std::string & partName, const char * ptype, const char * cmd, NxsToken & token, bool warnAsterisked, bool demandAllInds, NxsSetVectorItemValidator & v);
+ void ReadPartitionDef(NxsPartition &np, NxsLabelToIndicesMapper <m, const std::string & partName, const char * ptype, const char * cmd, NxsToken & token, bool warnAsterisked, bool demandAllInds, bool storeAsPartition);
+ virtual bool TolerateEOFInBlock() const
+ {
+ return false;
+ }
+ void WarnDangerousContent(const std::string &s, const NxsToken &t);
+ void WarnDangerousContent(const std::string &s, const ProcessedNxsToken &t);
+
+ void WriteBasicBlockCommands(std::ostream & out) const;
+ virtual void WriteSkippedCommands(std::ostream & out) const;
+ // used internally to deal with multiple blocks spawning the same TAXA block
+ virtual bool SwapEquivalentTaxaBlock(NxsTaxaBlockAPI * )
+ {
+ return false;
+ }
+ protected:
+ void SkipCommand(NxsToken & token);
+
+ NxsCommandResult HandleBasicBlockCommands(NxsToken & token);
+ void DemandEndSemicolon(NxsToken &token, const char *contextString) const;
+ void DemandEquals(NxsToken &token, const char *contextString) const;
+ void DemandEquals(ProcessedNxsCommand::const_iterator &tokIt, const ProcessedNxsCommand::const_iterator & endIt, const char *contextString) const ;
+ void DemandIsAtEquals(NxsToken &token, const char *contextString) const;
+ unsigned DemandPositiveInt(NxsToken &token, const char *contextString) const;
+ void GenerateNxsException(NxsToken &token, const char *message = NULL) const;
+ void GenerateUnexpectedTokenNxsException(NxsToken &token, const char *expected = NULL) const;
+ bool isEmpty; /* true if this object is currently storing data */
+ bool isEnabled; /* true if this block is currently ebabled */
+ bool isUserSupplied; /* true if this object has been read from a file; false otherwise */
+ NxsReader *nexusReader; /* pointer to the Nexus file reader object */
+ NxsBlock *next; /* DEPRECATED field pointer to next block in list */
+ NxsString id; /* holds name of block (e.g., "DATA", "TREES", etc.) */
+ std::string title; /* holds the title of the block empty by default */
+ std::string blockIDString; /* Mesquite generates these. I don't know what they are for */
+ bool linkAPI;
+ bool autoTitle; /* true if the title was generated internally*/
+ bool storeSkippedCommands;
+ std::list<ProcessedNxsCommand> skippedCommands; /* commands accumulate by SkipCommand or by some other means */
+
+ virtual void Read(NxsToken &token);
+ private:
+ NxsBlock &operator=(const NxsBlock &other); /*intentionally not defined because of aliasing issues */
+
+ };
+
+class NxsBlockFactory
+ {
+ public:
+ virtual ~NxsBlockFactory()
+ {
+ }
+ virtual NxsBlock * GetBlockReaderForID(const std::string & id, NxsReader *reader, NxsToken *token) = 0;
+ virtual void BlockError(NxsBlock *b)
+ {
+ delete b;
+ }
+ virtual void BlockSkipped(NxsBlock *b)
+ {
+ delete b;
+ }
+ };
+
+/*----------------------------------------------------------------------------------------------------------------------
[TRUNCATED]
To get the complete diff run:
svnlook diff /svnroot/phylobase -r 736
More information about the Phylobase-commits
mailing list