File: testWrite.cc

package info (click to toggle)
srf 0.1%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 3,972 kB
  • sloc: cpp: 1,165; sh: 558; makefile: 40
file content (79 lines) | stat: -rw-r--r-- 1,669 bytes parent folder | download | duplicates (3)
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
//
#include <cstdlib>
#include <ios>
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <stddef.h>
#include <SRF_util.hh>
#include <SRF_File.hh>
#include <SRF_ReadSet.hh>
#include <SRF_Container.hh>

using namespace std;

template <class T>
std::string SRF_to_string(T t, std::ios_base & (*f)(std::ios_base&))
{
  std::ostringstream oss;
  oss << f << t;
  return oss.str();
}   

int main(int argc, char **argv)
{
    SRF_File::openType mode = SRF_File::openTypeWrite;
    SRF_File file( "myFirstSSRFFile", mode );
    ifstream infile;
    SRF_Container container;

    if ( argc != 2 )
    {
	std::cout << "Usage: writer <input file>\n";
	exit(1);
    }


    infile.open (argv[1], ifstream::in);

    container.setup( "Test",
                     "0.0" );

    container.write( file.getFile() );

    SRF_ReadSet newReadSet;
    newReadSet.setup( "Test", "" );

    int readIdCounter = 0;

    int a,b,c,d;
    string str;
    std::vector<SRF_BasePrb> prbs;

    std::vector<ztr_t> ztrBlobs;
    std::vector<std::string> readIds;
    while( infile.good() )
    {
        infile >> a >> skipws >> b >> skipws >> c >> skipws >> d >> skipws >> str; 
        Read* read = SRF_create_read( str.c_str(), prbs );
        ztr_t* ztr = NULL;
        ztr = SRF_output_ztr( read );

        string readId;
        readId = SRF_to_string<int>(readIdCounter, std::dec);
        ztrBlobs.push_back( *ztr );
        readIds.push_back( readId );
        readIdCounter++;

	read_deallocate(read);
    }
    newReadSet.write( file.getFile(), ztrBlobs, readIds );

    /* FIXME: memory leak on ztr here still */

    infile.close();

    return 0;
}