File: uidjar.cpp

package info (click to toggle)
aethera 0.9.3-7
  • links: PTS
  • area: main
  • in suites: woody
  • size: 8,588 kB
  • ctags: 7,282
  • sloc: cpp: 64,544; sh: 9,913; perl: 1,756; makefile: 1,680; python: 258
file content (111 lines) | stat: -rw-r--r-- 2,515 bytes parent folder | download
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
109
110
111
/***************************************************************************
                uidjar.cpp  -  the UID jar interface class 
                             -------------------
    begin                : Wed Mar 14 19:02:00 EET 2001
    copyright            : (C) 2001 by theKompany (www.thekompany.com>
    author               : Eugen Constantinescu
    email                : eug@thekompany.com
 ***************************************************************************/

#include <uidjar.h>
#include <stdio.h>

UIDJar::UIDJar()
{
}
        
UIDJar::~UIDJar()
{
}
       
void UIDJar::loadLists()
{	
  // load the received UID
  ifstream rcvFile(rcvFileName.c_str());
  
  printf("\nLoad the UID from file:%s\n", rcvFileName.c_str());
  fflush(stdout);
  
  string uidString;
  UIDINFO uidData;
    
  if( rcvFile )
  {
    while( rcvFile )
    {
      // init
      uidString="";
      uidData.info="";
      uidData.rcvTime=0;
      
      rcvFile >> uidString;
      rcvFile >> uidData.info;
			rcvFile >> uidData.rcvTime;
			// insert the new UID in the map
			if( uidString.size() )
        rcvList.insert(UIDValuePair(uidString, uidData));
    }
    rcvFile.close();
  }

  printf("\n********* UIDJAR ********* = %u\n", rcvList.size());
  fflush(stdout);
    
  // load the deleted UID
  ifstream delFile(delFileName.c_str());
  if( delFile )
  {
    while( delFile )
    {
      // init
      uidString="";
      uidData.info="";
      uidData.rcvTime=0;
      
      delFile >> uidString;
      delFile >> uidData.info;
			delFile >> uidData.rcvTime;
			// A new UID is ready to be deleted :)
			if( uidString.size() )
        trashList.insert(UIDValuePair(uidString, uidData));
    }
    delFile.close();
  }
}

void UIDJar::saveLists()
{
//  printf("\n********* UIDJAR SAVE ********* = %u\n", rcvList.size());
//  fflush(stdout);
    
  ofstream rcvFile(rcvFileName.c_str());
  if( rcvFile )
  {
		for(UIDMap::iterator it=rcvList.begin(); it!=rcvList.end(); ++it)
		{
      rcvFile << (*it).first;
			rcvFile << " ";
      rcvFile << (*it).second.info;
			rcvFile << " ";
			rcvFile << (*it).second.rcvTime;
			rcvFile << "\n";
		}
    rcvFile.close();
  }
  		
  ofstream delFile(delFileName.c_str());
  if( delFile )
  {
		for(UIDMap::iterator it=trashList.begin(); it!=trashList.end(); ++it)
		{
      delFile << (*it).first;
			delFile << " ";
      delFile << (*it).second.info;
			delFile << " ";
			delFile << (*it).second.rcvTime;
			delFile << "\n";
		}
    delFile.close();
  }
}