From 1f5f8a22e9c584f709d4b34d2e4d24eaad2d5544 Mon Sep 17 00:00:00 2001
From: LAPTOP-SNT8I5JK\Boounion <Chenluhua@qq.com>
Date: 星期六, 24 五月 2025 15:11:56 +0800
Subject: [PATCH] 1.test
---
SourceCode/Bond/Servo/CAttributeVector.cpp | 36 +++++++++++++++++++++++++++++++++---
1 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/SourceCode/Bond/Servo/CAttributeVector.cpp b/SourceCode/Bond/Servo/CAttributeVector.cpp
index bb673f7..733c629 100644
--- a/SourceCode/Bond/Servo/CAttributeVector.cpp
+++ b/SourceCode/Bond/Servo/CAttributeVector.cpp
@@ -1,5 +1,6 @@
#include "stdafx.h"
#include "CAttributeVector.h"
+#include <algorithm>
namespace SERVO {
@@ -10,17 +11,39 @@
CAttributeVector::~CAttributeVector()
{
-
+ for (auto item : m_attributes) {
+ delete item;
+ }
+ m_attributes.clear();
}
- void CAttributeVector::addAttribute(CAttribute* pAttribute)
+ 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 m_attributes.size();
+ return (unsigned int)m_attributes.size();
}
void CAttributeVector::clear()
@@ -31,6 +54,13 @@
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();
--
Gitblit v1.9.3