Popping mad
unread,Nov 8, 2016, 4:16:09 PM11/8/16You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
/*
* =====================================================================================
*
* Filename: nodes.h
*
* Description: description of phylogentic nodes as per
* Fitch and Sannkoff as describd by Felenstein
*
* Version: 1.0
* Created: Nov 4 21:15:49 EDT 2016
* Revision: none
* Compiler: gcc
*
* Author: Ruben Safir,
* Company: LIU Thesis
*
* =====================================================================================
*/
#ifndef NODES_H
#define NODES_H
#include<iostream>
#include<string>
#include<vector>
namespace tree {
/* ==============================================================================
* Class NODE -
* Description - This is a node in the tree that must undergo parsimony evaluation
* ================================================================================
*/
template<class unk>
class NODE{
public:
//=========================LIFECYCLE=========================================
/* Constructor */
NODE( std::string xt, const unk &x , NODE<unk> *xcl= 0, NODE<unk> *xcr = 0, NODE<unk> *xp = 0 );
//NODE( std::string xt, unk &x , NODE<unk> *xcl= 0, NODE<unk> *xcr = 0, NODE<unk> *xp = 0 );
~NODE();
/* ==================== ACCESSORS ======================================= */
//no need for inline when you are defineing functions within the class definition
std::string trait()const{
return _trait;
}
unk states()const{
return _states;
};
NODE<unk> * cl()const{
return _cl;
};
NODE<unk> * cr()const{
return _cr;
};
NODE<unk> * p()const{
return _p;
};
void states(const unk &x){
_states = x;
}
void trait(std::string xt){
_trait = xt; //With genetics this is a A C G T although it is just a label
}
void cl(NODE<unk> *xcl){ //This is the left child node in the tree
_cl = xcl;
}
void cr(NODE<unk> *xcr){//This is the right node child node in the tree
_cr = xcr;
}
void p(NODE<unk> *xp){//This is the parent node in the tree
_p = xp;
}
/* ==================== MUTATORS ======================================= */
/* ==================== OPERATORS ======================================= */
//void display();
template <class T>
friend std::ostream& operator<<(std::ostream& os, const T&);
template<class T>
friend std::ostream& operator<<(std::ostream& os, const NODE<T> &);
protected:
/* ==================== DATA MEMBERS ======================================= */
private:
/* ==================== DATA MEMBERS ======================================= */
std::string _trait;
unk _states;
NODE<unk> * _cl, * _cr, * _p;
}; /* ----- end of template class NODE ----- */
template<class unk>
std::ostream& operator<<(std::ostream& os, const NODE<unk>& vec){
for( auto& y : vec.state() )
os << y << std::endl;
return os;
}
template<class unk>
NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
states(x);
trait(xt);
cl(xcl);
cr(xcr);
p(xp);
std::cout << trait() << " node " << "has the following states => " << std::endl;
}
//template<class unk>
//NODE<unk>::NODE( std::string xt, unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
// states(x);
// trait(xt);
// cl(xcl);
// cr(xcr);
// p(xp);
// std::cout << trait() << " node " << "has the following states => " << std::endl;
//}
template<class unk>
tree::NODE<unk>::~NODE<unk>(){
}
/*
* =====================================================================================
* Class: State
* Description: This describes a possible individual state or charactoristic
* =====================================================================================
*/
template<class cost>
class state
{
public:
/* ==================== LIFECYCLE ======================================= */
/* constructor */
//r is the minimum cost of a single state when compared to the child nodes
explicit state<cost>(std::string const xa, cost xr)
:_nam{xa}, _r{xr}
{
std::cout << "Building a state pair" << std::endl;
std::cout << "nam => " << nam() << "\tcost=> " << r() << std::endl;
};
/* ==================== ACCESSORS ======================================= */
std::string nam(){return _nam;};
cost r(){return _r;};
void r(cost b ){_r = b;};
/* ==================== MUTATORS ======================================= */
/* ==================== OPERATORS ======================================= */
/* ==================== DATA MEMBERS ======================================= */
protected:
private:
std::string _nam;
cost _r;
}; /* ----- end of class State ----- */
/*
* =====================================================================================
* Class: Pstates
* Description: vector of all possible states
* =====================================================================================
*/
template<class cost>
class Pstates
{
public:
/* ==================== LIFECYCLE ======================================= */
/* constructor */
Pstates (std::vector< state<cost> > x)
: _vstate{x}
{
for( auto& y : _vstate)
std::cout << y << std::endl;
};
// Pstates()
// : _vstate{0}
// {};
~Pstates (){}; /* destructor */
/* ==================== ACCESSORS ======================================= */
const std::vector< state<cost> >& vstate(){
return _vstate;
}
void vstate(std::vector< state<cost> > in ){
_vstate = in;
}
/* ==================== MUTATORS ======================================= */
/* ==================== OPERATORS ======================================= */
const Pstates& operator = ( const Pstates &other ); /* assignment operator */
/* ==================== DATA MEMBERS ======================================= */
protected:
private:
std::vector< state <cost> > _vstate;
}; /* ----- end of class Pstates ----- */
/* Overload ostream function */
template <class outcost>
std::ostream& operator << ( std::ostream &output, state<outcost> &p )
{
output << "nam => " << p.nam() << "\tcost=> " << p.r() << std::endl;
return output;
}
/*
template<class unk>
inline unk NODE<unk>::value(){ if(this != NULL) return _value; else return NULL; };
template<class unk>
inline void NODE<unk>::value(unk val){
_value = val;
};
*/
/*
template<class unk>
class LIST{
public:
LIST<unk>() : _at_front(0), _at_end(0), _size(0) {}
inline int size();
inline void insert(NODE<unk> *, unk);
inline void insert(unk);
inline void front(unk);
inline void up_size();
inline void down_size();
void display(ostream &os = cout);
void remove_front();
void remove_all();
void remove_item(unk);
void remove_item(NODE<unk> *);
NODE<unk> * find(unk);
NODE<unk> * find_all(unk, NODE<unk> * last = NULL );
~LIST<unk>();
private:
NODE<unk> *_at_front;
NODE<unk> *_at_end;
int _size;
LIST<unk>(const LIST<unk>&);
LIST<unk>& operator=( const LIST<unk>&);
};
*/
/*
template<class unk>
void LIST<unk>::display(ostream &os){
NODE<unk> * tmp = _at_front;
if (tmp == 0){
os << "No List" << endl;
return;
}
//unk i =0;
while(tmp != _at_end){
//cout << "Entering While Loop: "<< ++i << endl;
os << tmp->value() << ":";
tmp = tmp->next();
}
os << tmp->value() << endl;
}
*/
} /*---End of Namespace TREE---*/
#endif
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include<cstdlib>
#include <iostream>
#include "nodes.h"
using namespace std;
int main(int argv, char ** argc)
{
tree::state<int> a{"A", 65500};
tree::state<int> c{"C", 0};
tree::state<int> g{"G", 65500};
tree::state<int> t{"T", 65500};
vector< tree::state<int> > posible_states = {a,c,g,t};
tree::Pstates<int> node_status{posible_states};
tree::NODE<int> cr1{"T01", 3};
tree::NODE<int> cl1{"T00",2};
// tree::NODE<int> root{"T0",1};
// tree::NODE<Pstates<int> > cr1{"T01", 3};
// tree::NODE<Pstates<int> > cl1{"T00",2};
tree::NODE<tree::Pstates<int> > root{"T0",node_status};
return 0;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
when this compiles and reaches the last construction it loses parameters
|| g++ -Wall -ggdb -c nodes.cpp
|| g++ -Wall -ggdb -o fitch.o -c fitch.cpp
|| nodes.h: In instantiation of ‘tree::NODE<unk>::NODE(std::__cxx11::string, const unk&, tree::NODE<unk>*, tree::NODE<unk>*, tree::NODE<unk>*) [with unk = tree::Pstates<int>; std::__cxx11::string = std::__cxx11::basic_string<char>]’:
fitch.cpp|22 col 55| required from here
nodes.h|105 col 96| error: no matching function for call to ‘tree::Pstates<int>::Pstates()’
|| NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
|| ^
nodes.h|180 col 3| note: candidate: tree::Pstates<cost>::Pstates(std::vector<tree::state<cost> >) [with cost = int]
|| Pstates (std::vector< state<cost> > x)
|| ^~~~~~~
nodes.h|180 col 3| note: candidate expects 1 argument, 0 provided
nodes.h|174 col 7| note: candidate: tree::Pstates<int>::Pstates(const tree::Pstates<int>&)
|| class Pstates
|| ^~~~~~~
nodes.h|174 col 7| note: candidate expects 1 argument, 0 provided
make: *** [makefile|10| fitch.o] Error 1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
specifically right here...
fitch.cpp|22 col 55| required from here
nodes.h|105 col 96| error: no matching function for call to ‘tree::Pstates<int>::Pstates()’
|| NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
template<class unk>
NODE<unk>::NODE( std::string xt, const unk &x, NODE<unk> *xcl , NODE<unk> *xcr, NODE<unk> *xp ){
states(x);
trait(xt);
cl(xcl);
cr(xcr);
p(xp);
std::cout << trait() << " node " << "has the following states => " << std::endl;
}
it is not supposed to call Pstates<int>::Pstates()
I'm specifically sending the argument by reference. It is not supposed to be constructing a thing.