1 //******************************************************************
3 // Copyright 2016 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
21 #include "NSTopicsList.h"
22 #include "oic_malloc.h"
28 NSTopicsList::NSTopicsList(::NSTopicLL *topics, bool modify)
30 ::NSTopicLL *topicsNode = nullptr;
32 m_modifiable = modify;
34 while (topicsNode != nullptr)
36 m_topicsList.push_back(new NSTopic(
37 topicsNode->topicName, (NSTopic::NSTopicState)topicsNode->state));
38 topicsNode = topicsNode->next;
42 NSTopicsList::NSTopicsList(const NSTopicsList &topicsList)
44 for (auto it : topicsList.getTopicsList())
46 m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState()));
51 NSTopicsList &NSTopicsList::operator=(const NSTopicsList &topicsList)
53 for (auto it : topicsList.getTopicsList())
55 this->m_topicsList.push_back(new NSTopic(it.getTopicName(), it.getState()));
61 NSTopicsList::~NSTopicsList()
63 for (auto it : m_topicsList)
70 void NSTopicsList::addTopic(const std::string &topicName, NSTopic::NSTopicState state)
74 m_topicsList.push_back(new NSTopic(topicName, state));
78 //TODO: add exception code for Invalid operation
82 void NSTopicsList::removeTopic(const std::string &topicName)
86 for (auto it : m_topicsList)
88 if (it->getTopicName().compare(topicName) == 0)
90 m_topicsList.remove(it);
96 //TODO: add exception code for Invalid operation
100 std::list<NSTopic> NSTopicsList::getTopicsList() const
102 std::list<NSTopic> topicList;
103 for (auto it : m_topicsList)
105 NSTopic topic(it->getTopicName(), it->getState());
106 topicList.push_back(topic);
111 void NSTopicsList::unsetModifiability()
113 m_modifiable = false;