LAPTOP-SNT8I5JK\Boounion
2025-05-21 c0d56e6ac7ec15e232fb38c457eefc89cf80e9da
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
#include "stdafx.h"
#include "CAttributeVector.h"
#include <algorithm>
 
 
namespace SERVO {
    CAttributeVector::CAttributeVector()
    {
 
    }
 
    CAttributeVector::~CAttributeVector()
    {
        for (auto item : m_attributes) {
            delete item;
        }
        m_attributes.clear();
    }
 
    void CAttributeVector::addAttribute(CAttribute* pAttribute, BOOL bReplace/* = FALSE*/)
    {
        if (bReplace) {
            for (auto it = m_attributes.begin(); it != m_attributes.end(); ) {
                if ((*it)->getName().compare(pAttribute->getName()) == 0) {
                    delete (*it);
                    it = m_attributes.erase(it);
                }
                else {
                    ++it;
                }
            }
        }
 
        m_attributes.push_back(pAttribute);
    }
 
    void CAttributeVector::addAttributeVector(CAttributeVector& av)
    {
        for (auto item : av.m_attributes) {
            m_attributes.push_back(item);
        }
    }
 
    unsigned int CAttributeVector::size()
    {
        return (unsigned int)m_attributes.size();
    }
 
    void CAttributeVector::clear()
    {
        for (auto item : m_attributes) {
            delete item;
        }
        m_attributes.clear();
    }
 
    void CAttributeVector::sortWithWeight()
    {
        std::sort(m_attributes.begin(), m_attributes.end(), [](CAttribute* pAttribute1, CAttribute* pAttribut2) {
            return pAttribute1->getWeight() < pAttribut2->getWeight();
        });
    }
 
    bool CAttributeVector::empty()
    {
        return m_attributes.empty();
    }
 
    CAttribute* CAttributeVector::getAttribute(unsigned int index)
    {
        ASSERT(index < m_attributes.size());
        return m_attributes[index];
    }
}