2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @file IAttachment.cpp
20 * @author Pawel Misiak (p.misiak@samsung.com)
25 #include <dpl/log/log.h>
26 #include <Commons/Exception.h>
27 #include "Attachments.h"
28 #include "AttachmentFactory.h"
35 using namespace WrtDeviceApis::Commons;
38 //--------------------------------------------------------------------------
39 namespace WrtDeviceApis {
43 Attachments::Attachments() :
44 m_validAttachments(false)
49 Attachments::~Attachments()
54 IAttachmentPtr Attachments::appendAttachment(const std::string& fullPath,
57 LogDebug("enter, fullPath=" << fullPath);
58 IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
61 m_validAttachments = false;
62 m_attachments.push_back(tmpAttach);
66 void Attachments::appendAttachment(const IAttachmentPtr& attachment)
69 m_validAttachments = false;
70 m_attachments.push_back(attachment);
73 void Attachments::appendAttachments(const vector<IAttachmentPtr>& attachments)
76 back_insert_iterator< vector<IAttachmentPtr> >biit(m_attachments);
77 copy(attachments.begin(), attachments.end(), biit);
80 size_t Attachments::getAttachmentsCount() const
83 return m_attachments.size();
86 IAttachmentPtr Attachments::getAttachment(const size_t index) const
89 if (index >= m_attachments.size()) {
90 ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
92 return m_attachments[index];
95 void Attachments::removeAttachment(const size_t index)
98 if (index >= m_attachments.size()) {
99 ThrowMsg(OutOfRangeException, "Trying to get attachment out of range");
101 m_validAttachments = false;
102 m_attachments.erase(m_attachments.begin() + index);
105 void Attachments::removeAttachment(const IAttachmentPtr& attachment)
108 remove(m_attachments.begin(), m_attachments.end(), attachment),
109 m_attachments.end());
112 vector<IAttachmentPtr> Attachments::getAttachments() const
115 return m_attachments;
118 vector<string> Attachments::getAttachmentsFullPaths() const
120 vector<string> retVal;
122 for (size_t i = 0; i < m_attachments.size(); i++) {
123 retVal.push_back(m_attachments[i]->getFullPath());
128 vector<string> Attachments::getAttachmentsShortNames() const
130 vector<string> retVal;
132 for (size_t i = 0; i < m_attachments.size(); i++) {
133 retVal.push_back(m_attachments[i]->getShortName());
138 void Attachments::setAttachments(const vector<string>& attachments,
141 vector<string>::const_iterator it = attachments.begin();
143 m_attachments.clear();
144 while (it != attachments.end()) {
145 appendAttachment(*it, isVirtualPath);
150 void Attachments::setAttachments(const vector<IAttachmentPtr>& attachments)
152 m_attachments = attachments;
153 m_validAttachments = false;
156 bool Attachments::isAttachmentsValid() const
158 return m_validAttachments;
161 void Attachments::setAttachmentsValidity(bool state)
163 m_validAttachments = state;
166 const vector<IAttachmentPtr>& Attachments::getAttachmentsRef() const
168 return m_attachments;
171 void Attachments::saveAttachment(const string& /*destFileName*/,
172 const IAttachmentPtr& /*attachment*/)
174 // possible move it as a virtual function - to be clarified
179 void Attachments::setAttachmentWithExpand(const size_t index,
180 const std::string& fullPath,
184 if (index >= m_attachments.size()) {
185 m_attachments.resize(index + 1); // resize with empty ptr
187 IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
190 m_attachments[index] = tmpAttach;
191 m_validAttachments = false;
194 void Attachments::reverse()
196 std::reverse(m_attachments.begin(), m_attachments.end());
199 void Attachments::insertAttachment(const size_t index,
200 const std::string& fullPath,
203 IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
206 m_attachments.insert(m_attachments.begin() + index, tmpAttach);
207 m_validAttachments = false;
210 void Attachments::insertAttachmentWithExpand(const size_t index,
211 const std::string& fullPath,
215 if (index >= m_attachments.size()) {
216 m_attachments.resize(index); // resize with empty ptr
218 IAttachmentPtr tmpAttach = AttachmentFactory::createAttachment(
221 m_attachments.insert(m_attachments.begin() + index, tmpAttach);
222 m_validAttachments = false;