forked from ppdewolf/libmuargus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChSafeVarInfo.cpp
88 lines (80 loc) · 2.38 KB
/
ChSafeVarInfo.cpp
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
/*
* Argus Open Source
* Software to apply Statistical Disclosure Control techniques
*
* Copyright 2014 Statistics Netherlands
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the European Union Public Licence
* (EUPL) version 1.1, as published by the European Commission.
*
* You can find the text of the EUPL v1.1 on
* https://joinup.ec.europa.eu/software/page/eupl/licence-eupl
*
* This software is distributed on an "AS IS" basis without
* warranties or conditions of any kind, either express or implied.
*/
#include "ChSafeVarInfo.h"
#include <string>
#include <vector>
#include <stdio.h>
#include <string.h>
void CChSafeVarInfo::SetVarIndex(long *lVarIndex) {
if (m_lNVar >0){
m_lVarIndex = new long[m_lNVar];
memcpy(m_lVarIndex, lVarIndex, m_lNVar*sizeof(long));
}
}
std::string CChSafeVarInfo::GetStringFromFile()
{
FILE *fd;
std::string cstr;
char str[MAXRECORD];
fd = fopen(m_sFileName.c_str(),"r");
fseek(fd,m_lCurrFilePos,SEEK_SET);
fgets(str,MAXRECORD,fd);
cstr = str;
m_lCurrFilePos= ftell(fd);
fclose(fd);
return cstr;
}
bool CChSafeVarInfo::FillVariableCode()
{
FILE *fd;
std::string stempstr,stemp;
char str[MAXRECORD];
long icount;
int iseppos;
// First Clear previous array
sVariableCode.clear();
sVariableCode.resize(m_lNVar);
fd = fopen(m_sFileName.c_str(),"r");
fseek(fd,m_lCurrFilePos,SEEK_SET);
fgets((char *)str, MAXRECORD,fd); // fgets() returns a string including any LF, CR, CRLF, LFCR
str[strcspn(str,"\r\n")]=0; // Remove LF, CR, CRLF, LFCR, ... Important to do so for non-numeric variables!!!!
stempstr = str;
iseppos = stempstr.find(m_sSeperator,0);
icount = 0;
while (iseppos != -1) {
//stemp=stempstr.Left(iseppos);
stemp = stempstr.substr(0, iseppos);
//sVariableCode.SetAt(icount,stemp);
sVariableCode.at(icount) = stemp;
icount ++;
//stempstr.Delete (0,iseppos +1);
stempstr.erase(0,iseppos +1);
iseppos = stempstr.find(m_sSeperator,0);
if (iseppos == stempstr.npos) iseppos = -1; // std::string.find(x) returns npos if x is not found
}
if ((stempstr.length() == 0) || (icount < m_lNVar-1) || (icount > m_lNVar-1))
{
return false;
}
else
{
sVariableCode.at(icount) = stempstr;
}
m_lCurrFilePos = ftell(fd);
fclose(fd);
return true;
}