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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
#include "ncl/ncl.h"
using namespace std;
NxsTaxaBlock *taxa = NULL;
NxsTreesBlock *trees = NULL;
class MyReader : public NxsReader
{
public:
ifstream inf;
ofstream outf;
MyReader(char *infname, char *outfname) : NxsReader()
{
inf.open(infname, ios::binary);
outf.open(outfname);
}
~MyReader()
{
inf.close();
outf.close();
}
void ExecuteStarting() {}
void ExecuteStopping() {}
bool EnteringBlock(NxsString blockName)
{
cout << "Reading \"" << blockName << "\" block..." << endl;
outf << "Reading \"" << blockName << "\" block..." << endl;
// Returning true means it is ok to delete any data associated with
// blocks of this type read in previously
//
return true;
}
void SkippingBlock(NxsString blockName)
{
cout << "Skipping unknown block (" << blockName << ")..." << endl;
outf << "Skipping unknown block (" << blockName << ")..." << endl;
}
void SkippingDisabledBlock(NxsString )
{
}
void OutputComment(const NxsString &msg)
{
outf << msg;
}
void NexusError(NxsString msg, file_pos pos, long line, long col)
{
cerr << endl;
cerr << "Error found at line " << line;
cerr << ", column " << col;
cerr << " (file position " << pos << "):" << endl;
cerr << msg << endl;
outf << endl;
outf << "Error found at line " << line;
outf << ", column " << col;
outf << " (file position " << pos << "):" << endl;
outf << msg << endl;
exit(0);
}
};
class MyToken : public NxsToken
{
public:
MyToken(istream &is, ostream &os)
:NxsToken(is),
out(os)
{
}
void OutputComment(const NxsString &msg)
{
cout << msg << endl;
out << msg << endl;
}
private:
ostream &out;
};
int main(int , char *argv[])
{
taxa = new NxsTaxaBlock();
trees = new NxsTreesBlock(taxa);
MyReader nexus(argv[1], argv[2]);
nexus.Add(taxa);
nexus.Add(trees);
MyToken token(nexus.inf, nexus.outf);
nexus.Execute(token);
taxa->Report(nexus.outf);
trees->Report(nexus.outf);
return 0;
}
|