1 
2 //
3 // This source file is part of appleseed.
4 // Visit https://appleseedhq.net/ for additional information and resources.
5 //
6 // This software is released under the MIT license.
7 //
8 // Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9 // Copyright (c) 2014-2018 Francois Beaune, The appleseedhq Organization
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining a copy
12 // of this software and associated documentation files (the "Software"), to deal
13 // in the Software without restriction, including without limitation the rights
14 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 // copies of the Software, and to permit persons to whom the Software is
16 // furnished to do so, subject to the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be included in
19 // all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27 // THE SOFTWARE.
28 //
29 
30 // Interface header.
31 #include "specializedapiarrays.h"
32 
33 // Standard headers.
34 #include <cassert>
35 #include <string>
36 #include <vector>
37 
38 using namespace std;
39 
40 namespace foundation
41 {
42 
43 APPLESEED_DEFINE_APIARRAY(FloatArray);
44 APPLESEED_DEFINE_APIARRAY(DoubleArray);
45 APPLESEED_DEFINE_APIARRAY(DictionaryArray);
46 
47 
48 //
49 // StringArray class implementation.
50 //
51 
52 struct StringArray::Impl
53   : public vector<string>
54 {
55 };
56 
StringArray()57 StringArray::StringArray()
58   : impl(new Impl())
59 {
60 }
61 
StringArray(const StringArray & rhs)62 StringArray::StringArray(const StringArray& rhs)
63   : impl(new Impl(*rhs.impl))
64 {
65 }
66 
StringArray(const size_type size,const value_type * values)67 StringArray::StringArray(
68     const size_type     size,
69     const value_type*   values)
70   : impl(new Impl())
71 {
72     assert(size > 0);
73     assert(values);
74 
75     impl->resize(size);
76 
77     for (size_t i = 0; i < size; ++i)
78         (*impl)[i] = values[i];
79 }
80 
~StringArray()81 StringArray::~StringArray()
82 {
83     delete impl;
84 }
85 
operator =(const StringArray & rhs)86 StringArray& StringArray::operator=(const StringArray& rhs)
87 {
88     *impl = *rhs.impl;
89     return *this;
90 }
91 
size() const92 StringArray::size_type StringArray::size() const
93 {
94     return impl->size();
95 }
96 
empty() const97 bool StringArray::empty() const
98 {
99     return impl->empty();
100 }
101 
clear()102 void StringArray::clear()
103 {
104     impl->clear();
105 }
106 
reserve(const size_type count)107 void StringArray::reserve(const size_type count)
108 {
109     impl->reserve(count);
110 }
111 
resize(const size_type new_size)112 void StringArray::resize(const size_type new_size)
113 {
114     impl->resize(new_size);
115 }
116 
push_back(const value_type val)117 void StringArray::push_back(const value_type val)
118 {
119     impl->push_back(val);
120 }
121 
set(const size_type pos,const value_type val)122 void StringArray::set(const size_type pos, const value_type val)
123 {
124     assert(val);
125     (*impl)[pos] = val;
126 }
127 
operator [](const size_type pos) const128 StringArray::value_type StringArray::operator[](const size_type pos) const
129 {
130     return (*impl)[pos].c_str();
131 }
132 
133 }   // namespace foundation
134