|
| 1 | +////////////////////////////////////////////////////////////////////////// |
| 2 | +// |
| 3 | +// Copyright (c) 2025, Cinesite VFX Ltd. All rights reserved. |
| 4 | +// |
| 5 | +// Redistribution and use in source and binary forms, with or without |
| 6 | +// modification, are permitted provided that the following conditions are |
| 7 | +// met: |
| 8 | +// |
| 9 | +// * Redistributions of source code must retain the above copyright |
| 10 | +// notice, this list of conditions and the following disclaimer. |
| 11 | +// |
| 12 | +// * Redistributions in binary form must reproduce the above copyright |
| 13 | +// notice, this list of conditions and the following disclaimer in the |
| 14 | +// documentation and/or other materials provided with the distribution. |
| 15 | +// |
| 16 | +// * Neither the name of Image Engine Design nor the names of any |
| 17 | +// other contributors to this software may be used to endorse or |
| 18 | +// promote products derived from this software without specific prior |
| 19 | +// written permission. |
| 20 | +// |
| 21 | +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
| 22 | +// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 23 | +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 24 | +// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 25 | +// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 26 | +// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 27 | +// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 28 | +// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
| 29 | +// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
| 30 | +// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 31 | +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 32 | +// |
| 33 | +////////////////////////////////////////////////////////////////////////// |
| 34 | + |
| 35 | +#include "IECore/ObjectMatrix.h" |
| 36 | + |
| 37 | +#include "IECore/MurmurHash.h" |
| 38 | + |
| 39 | +using namespace IECore; |
| 40 | + |
| 41 | +IE_CORE_DEFINEOBJECTTYPEDESCRIPTION( ObjectMatrix ); |
| 42 | + |
| 43 | +ObjectMatrix::ObjectMatrix( size_t rows, size_t columns ) |
| 44 | + : m_rows( rows ), m_columns( columns ) |
| 45 | +{ |
| 46 | + m_members.resize( rows * columns, nullptr ); |
| 47 | +} |
| 48 | + |
| 49 | +ObjectMatrix::~ObjectMatrix() |
| 50 | +{ |
| 51 | +} |
| 52 | + |
| 53 | +size_t ObjectMatrix::numRows() const |
| 54 | +{ |
| 55 | + return m_rows; |
| 56 | +} |
| 57 | + |
| 58 | +size_t ObjectMatrix::numColumns() const |
| 59 | +{ |
| 60 | + return m_columns; |
| 61 | +} |
| 62 | + |
| 63 | +void ObjectMatrix::resize( size_t rows, size_t columns ) |
| 64 | +{ |
| 65 | + MemberContainer originalMembers( m_members ); |
| 66 | + m_members.clear(); |
| 67 | + m_members.resize( rows * columns, nullptr ); |
| 68 | + for( size_t i = 0; i < rows && i < m_rows; ++i ) |
| 69 | + { |
| 70 | + for( size_t j = 0; j < columns && j < m_columns; ++j ) |
| 71 | + { |
| 72 | + m_members[ i * columns + j ] = originalMembers[ i * m_columns + j ]; |
| 73 | + } |
| 74 | + } |
| 75 | + m_rows = rows; |
| 76 | + m_columns = columns; |
| 77 | +} |
| 78 | + |
| 79 | +void ObjectMatrix::copyFrom( const Object *other, CopyContext *context ) |
| 80 | +{ |
| 81 | + Object::copyFrom( other, context ); |
| 82 | + const ObjectMatrix *tOther = static_cast<const ObjectMatrix *>( other ); |
| 83 | + m_members.resize( tOther->m_members.size() ); |
| 84 | + for( MemberContainer::size_type i = 0; i < m_members.size(); ++i ) |
| 85 | + { |
| 86 | + if( !tOther->m_members[i] ) |
| 87 | + { |
| 88 | + m_members[i] = nullptr; |
| 89 | + } |
| 90 | + else |
| 91 | + { |
| 92 | + m_members[i] = context->copy<Object>( tOther->m_members[i].get() ); |
| 93 | + } |
| 94 | + } |
| 95 | + m_rows = tOther->m_rows; |
| 96 | + m_columns = tOther->m_columns; |
| 97 | +} |
| 98 | + |
| 99 | +void ObjectMatrix::save( Object::SaveContext *context ) const |
| 100 | +{ |
| 101 | + Object::save( context ); |
| 102 | + throw IECore::NotImplementedException( "ObjectMatrix::save" ); |
| 103 | +} |
| 104 | + |
| 105 | +void ObjectMatrix::load( Object::LoadContextPtr context ) |
| 106 | +{ |
| 107 | + Object::load( context ); |
| 108 | + throw IECore::NotImplementedException( "ObjectMatrix::load" ); |
| 109 | +} |
| 110 | + |
| 111 | +bool ObjectMatrix::isEqualTo( const Object *other ) const |
| 112 | +{ |
| 113 | + if( !Object::isEqualTo( other ) ) |
| 114 | + { |
| 115 | + return false; |
| 116 | + } |
| 117 | + const ObjectMatrix *tOther = static_cast<const ObjectMatrix *>( other ); |
| 118 | + if( m_rows != tOther->m_rows || m_columns != tOther->m_columns ) |
| 119 | + { |
| 120 | + return false; |
| 121 | + } |
| 122 | + for( MemberContainer::size_type i = 0; i < m_members.size(); ++i ) |
| 123 | + { |
| 124 | + if( m_members[i] ) |
| 125 | + { |
| 126 | + if( !tOther->m_members[i] || !m_members[i]->isEqualTo( tOther->m_members[i].get() ) ) |
| 127 | + { |
| 128 | + return false; |
| 129 | + } |
| 130 | + } |
| 131 | + else |
| 132 | + { |
| 133 | + if( tOther->m_members[i] ) |
| 134 | + { |
| 135 | + return false; |
| 136 | + } |
| 137 | + } |
| 138 | + } |
| 139 | + |
| 140 | + return true; |
| 141 | +} |
| 142 | + |
| 143 | +void ObjectMatrix::memoryUsage( Object::MemoryAccumulator &a ) const |
| 144 | +{ |
| 145 | + Object::memoryUsage( a ); |
| 146 | + for( const auto &m : m_members ) |
| 147 | + { |
| 148 | + if( m ) |
| 149 | + { |
| 150 | + a.accumulate( m.get() ); |
| 151 | + } |
| 152 | + } |
| 153 | + a.accumulate( sizeof( m_rows ) ); |
| 154 | + a.accumulate( sizeof( m_columns ) ); |
| 155 | +} |
| 156 | + |
| 157 | +void ObjectMatrix::hash( MurmurHash &h ) const |
| 158 | +{ |
| 159 | + Object::hash( h ); |
| 160 | + for( const auto &m : m_members ) |
| 161 | + { |
| 162 | + if( m ) |
| 163 | + { |
| 164 | + m->hash( h ); |
| 165 | + } |
| 166 | + else |
| 167 | + { |
| 168 | + h.append( 0 ); |
| 169 | + } |
| 170 | + } |
| 171 | + h.append( m_rows ); |
| 172 | + h.append( m_columns ); |
| 173 | +} |
0 commit comments