
#include <typeinfo>
#include <iostream.h>
#include <string>
#include "pf/bitstring.h"
#include "pf/exception.h"
#include "pf/storage.h"
#include "pf/debug.h"

int main(void)
{
    debugOutputCout();
        
    cout << "\npfBitString - testing... \n" << endl;

    pfBitString A("110010101111"), C;
    string s;
    
    C = A;
    
    cout << "A:    " << A << "  length: " << A.length() << endl;    
    cout << "C:    " << C << "  length: " << C.length() << endl;    
    cout << "A==C: " << ((A==C) ? "same\n" : "different\n") << endl;

    cout << "C.putFirstBits(\"101\")" << endl; C.putFirstBits("101");
    cout << "C:    " << C << "  length: " << C.length() << endl; 
    cout << "C.putLastBits(\"0011\")" << endl; C.putLastBits("0011");
    cout << "C:    " << C << "  length: " << C.length() << endl;
    
    cout << "A==C: " << ((A==C) ? "same\n" : "different\n") << endl;
        
    cout << "A:    " << A << "  length: " << A.length() << endl;   
    cout << "A.readBits(1,4):   " << A.readBits(1,4) << endl;
    cout << "A.getFirstBits(4): " << A.getFirstBits(4) << endl;
    cout << "A.getLastBits(4):  " << A.getLastBits(4) << endl;
    cout << "A:    " << A << "  length: " << A.length() << endl;
    cout << "A.putFirstBits(11,4): " << endl; A.putFirstBits(11, 4);
    cout << "A.putLastBits(13,4): " << endl; A.putLastBits(13, 4);  
    cout << "A:    " << A << "  length: " << A.length() << endl;    
    cout << "A.getLastBits(4):  " << A.getLastBits(4) << endl;
    cout << "A:    " << A << "  length: " << A.length() << endl;

    
    try{
        cout << "A.toString(x): " << A.toString(1) << endl;
    }
    catch(pfOutOfRangeException &ex){
            ex.printInfo();
            delete (pfOutOfRangeException *)&ex;
    }
    cout << "A:    " << A << "  length: " << A.length() << endl;

    cout << "\nTesting storage w/ pfBitString" << endl;
    pfStorage st;
    string bs("mybitstring");
    st.defineBitString(bs);
    st.setBitString(bs, A);
    pfBitString BS = st.getBitString(bs);
    debugString("BS from storage: ", BS.toString());
    st.print();
    
    return 0;
}

