blob: 3d63a3d0f5abcfaeb932463a756570fa1bc45612 [file] [log] [blame]
akmhoque53353462014-04-22 08:43:45 -05001#include <string>
2#include <iostream>
3#include <fstream>
4#include <pwd.h>
5#include <cstdlib>
6#include <unistd.h>
7
8#include "sequencing-manager.hpp"
9
10namespace nlsr {
11
12using namespace std;
13
14void
15SequencingManager::splittSequenceNo(uint64_t seqNo)
16{
17 m_combinedSeqNo = seqNo;
18 m_adjLsaSeq = (m_combinedSeqNo & 0xFFFFF);
19 m_corLsaSeq = ((m_combinedSeqNo >> 20) & 0xFFFFF);
20 m_nameLsaSeq = ((m_combinedSeqNo >> 40) & 0xFFFFF);
21}
22
23void
24SequencingManager::combineSequenceNo()
25{
26 m_combinedSeqNo = 0;
27 m_combinedSeqNo = m_combinedSeqNo | m_adjLsaSeq;
28 m_combinedSeqNo = m_combinedSeqNo | (m_corLsaSeq << 20);
29 m_combinedSeqNo = m_combinedSeqNo | (m_nameLsaSeq << 40);
30}
31
32void
33SequencingManager::writeSeqNoToFile()
34{
35 std::ofstream outputFile(m_seqFileNameWithPath.c_str(), ios::binary);
36 outputFile << m_combinedSeqNo;
37 outputFile.close();
38}
39
40void
41SequencingManager::initiateSeqNoFromFile()
42{
43 cout << "Seq File Name: " << m_seqFileNameWithPath << endl;
44 std::ifstream inputFile(m_seqFileNameWithPath.c_str(), ios::binary);
akmhoque157b0a42014-05-13 00:26:37 -050045 if (inputFile.good()) {
akmhoque53353462014-04-22 08:43:45 -050046 inputFile >> m_combinedSeqNo;
47 splittSequenceNo(m_combinedSeqNo);
48 m_adjLsaSeq += 10;
49 m_corLsaSeq += 10;
50 m_nameLsaSeq += 10;
51 combineSequenceNo();
52 inputFile.close();
53 }
akmhoque157b0a42014-05-13 00:26:37 -050054 else {
akmhoque53353462014-04-22 08:43:45 -050055 splittSequenceNo(0);
56 }
57}
58
59void
60SequencingManager::setSeqFileName(string filePath)
61{
62 m_seqFileNameWithPath = filePath;
akmhoque157b0a42014-05-13 00:26:37 -050063 if (m_seqFileNameWithPath.empty()) {
akmhoque53353462014-04-22 08:43:45 -050064 m_seqFileNameWithPath = getUserHomeDirectory();
65 }
66 m_seqFileNameWithPath = m_seqFileNameWithPath + "/nlsrSeqNo.txt";
67}
68
69string
70SequencingManager::getUserHomeDirectory()
71{
72 string homeDirPath(getpwuid(getuid())->pw_dir);
akmhoque157b0a42014-05-13 00:26:37 -050073 if (homeDirPath.empty()) {
akmhoque53353462014-04-22 08:43:45 -050074 homeDirPath = getenv("HOME");
75 }
76 return homeDirPath;
77}
78
79ostream&
80operator<<(ostream& os, const SequencingManager& sm)
81{
82 std::cout << "----SequencingManager----" << std::endl;
83 std::cout << "Adj LSA seq no: " << sm.getAdjLsaSeq() << endl;
84 std::cout << "Cor LSA Seq no: " << sm.getCorLsaSeq() << endl;
85 std::cout << "Name LSA Seq no: " << sm.getNameLsaSeq() << endl;
86 std::cout << "Combined LSDB Seq no: " << sm.getCombinedSeqNo() << endl;
87 return os;
88}
89
90}//namespace nlsr
91
92