/src/FreeImage/Source/OpenEXR/IlmImf/ImfOpaqueAttribute.cpp

https://bitbucket.org/cabalistic/ogredeps/ · C++ · 125 lines · 61 code · 25 blank · 39 comment · 3 complexity · e92389e8e392a888755dac32f90c49fd MD5 · raw file

  1. ///////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 2004, Industrial Light & Magic, a division of Lucas
  4. // Digital Ltd. LLC
  5. //
  6. // All rights reserved.
  7. //
  8. // Redistribution and use in source and binary forms, with or without
  9. // modification, are permitted provided that the following conditions are
  10. // met:
  11. // * Redistributions of source code must retain the above copyright
  12. // notice, this list of conditions and the following disclaimer.
  13. // * Redistributions in binary form must reproduce the above
  14. // copyright notice, this list of conditions and the following disclaimer
  15. // in the documentation and/or other materials provided with the
  16. // distribution.
  17. // * Neither the name of Industrial Light & Magic nor the names of
  18. // its contributors may be used to endorse or promote products derived
  19. // from this software without specific prior written permission.
  20. //
  21. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. //
  33. ///////////////////////////////////////////////////////////////////////////
  34. //-----------------------------------------------------------------------------
  35. //
  36. // class OpaqueAttribute
  37. //
  38. //-----------------------------------------------------------------------------
  39. #include <ImfOpaqueAttribute.h>
  40. #include "Iex.h"
  41. #include <string.h>
  42. namespace Imf {
  43. OpaqueAttribute::OpaqueAttribute (const char typeName[]):
  44. _typeName (strlen (typeName) + 1),
  45. _dataSize (0)
  46. {
  47. strcpy (_typeName, typeName);
  48. }
  49. OpaqueAttribute::OpaqueAttribute (const OpaqueAttribute &other):
  50. _typeName (strlen (other._typeName) + 1),
  51. _dataSize (other._dataSize),
  52. _data (other._dataSize)
  53. {
  54. strcpy (_typeName, other._typeName);
  55. _data.resizeErase (other._dataSize);
  56. memcpy ((char *) _data, (const char *) other._data, other._dataSize);
  57. }
  58. OpaqueAttribute::~OpaqueAttribute ()
  59. {
  60. // empty
  61. }
  62. const char *
  63. OpaqueAttribute::typeName () const
  64. {
  65. return _typeName;
  66. }
  67. Attribute *
  68. OpaqueAttribute::copy () const
  69. {
  70. return new OpaqueAttribute (*this);
  71. }
  72. void
  73. OpaqueAttribute::writeValueTo (OStream &os, int version) const
  74. {
  75. Xdr::write <StreamIO> (os, _data, _dataSize);
  76. }
  77. void
  78. OpaqueAttribute::readValueFrom (IStream &is, int size, int version)
  79. {
  80. _data.resizeErase (size);
  81. _dataSize = size;
  82. Xdr::read <StreamIO> (is, _data, size);
  83. }
  84. void
  85. OpaqueAttribute::copyValueFrom (const Attribute &other)
  86. {
  87. const OpaqueAttribute *oa = dynamic_cast <const OpaqueAttribute *> (&other);
  88. if (oa == 0 || strcmp (_typeName, oa->_typeName))
  89. {
  90. THROW (Iex::TypeExc, "Cannot copy the value of an "
  91. "image file attribute of type "
  92. "\"" << other.typeName() << "\" "
  93. "to an attribute of type "
  94. "\"" << _typeName << "\".");
  95. }
  96. _data.resizeErase (oa->_dataSize);
  97. _dataSize = oa->_dataSize;
  98. memcpy ((char *) _data, (const char *) oa->_data, oa->_dataSize);
  99. }
  100. } // namespace Imf