LAPTOP-SNT8I5JK\Boounion
2025-09-05 fc8d367963a16de61dfbc4a0ff34c78c91ec2cfe
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
#include "stdafx.h"
#include "CReport.h"
 
 
namespace SERVO {
    CReport::CReport()
    {
        m_nReportId = 0;
    }
 
    CReport::CReport(unsigned int reportId, std::vector<unsigned int>& vids)
    {
        m_nReportId = reportId;
        for (auto vid : vids) {
            m_vids.push_back(vid);
        }
    }
 
    CReport::~CReport()
    {
 
    }
 
    unsigned int CReport::getReportId()
    {
        return m_nReportId;
    }
 
    BOOL CReport::addVariable(CVariable* pVariable)
    {
        ASSERT(pVariable);
        if (getVariable(pVariable->getVarialbleId()) != nullptr) {
            return FALSE;
        }
 
        m_variabels.push_back(pVariable);
        return TRUE;
    }
 
    BOOL CReport::deleteVarialble(unsigned int nVarialbleId)
    {
        BOOL bDelete = FALSE;
        for (auto iter = m_variabels.begin(); iter != m_variabels.end(); ++iter) {
            if (nVarialbleId == (*iter)->getVarialbleId()) {
                m_variabels.erase(iter);
                bDelete = TRUE;
                break;
            }
        }
 
        return bDelete;
    }
 
    CVariable* CReport::getVariable(unsigned int nVarialbleId)
    {
        for (auto item : m_variabels) {
            if (nVarialbleId == item->getVarialbleId()) {
                return item;
            }
        }
 
        return nullptr;
    }
 
    std::vector<CVariable*>& CReport::getVariables()
    {
        return m_variabels;
    }
 
    std::string CReport::getVariablesIdsText()
    {
        std::string strResult, strName;
        for (int i = 0; i < m_vids.size(); i++) {
            strResult += std::to_string(m_vids[i]);
            strResult += "(";
            strResult += (getVariableName(m_vids[i], strName) ?
                strName : _T("null"));
            strResult += ")";
            if (i != m_vids.size() - 1) {
                strResult += ",";
            }
        }
 
        return strResult;
    }
 
    bool CReport::getVariableName(unsigned int vid, std::string& strName)
    {
        for (auto item : m_variabels) {
            if (item->getVarialbleId() == vid) {
                strName = item->getName();
                return true;
            }
        }
 
        return false;
    }
}