fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / System / FileIO / OSB / OSGOSBShaderParameterMIntElement.cpp
blob4d89dca996e49160004fb748b8e5855bb26ede26
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2013 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
18 * *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
23 * *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
27 * *
28 \*---------------------------------------------------------------------------*/
30 #include "OSGOSBShaderParameterMIntElement.h"
32 #include "OSGOSBRootElement.h"
34 OSG_BEGIN_NAMESPACE
36 /*-------------------------------------------------------------------------*/
37 /* OSBShaderParameterMIntElement */
38 /*-------------------------------------------------------------------------*/
40 /*! Reads the ShaderParameterMInt from OpenSG 1.x and stores it's value
41 so OSBSHLChunkElement can add it as a uniform, see
42 OSBSHLChunkElement::postRead().
45 /*-------------------------------------------------------------------------*/
46 /* Static members */
48 OSBElementRegistrationHelper<OSBShaderParameterMIntElement>
49 OSBShaderParameterMIntElement::_regHelper =
50 OSBElementRegistrationHelper<OSBShaderParameterMIntElement>(
51 "ShaderParameterMInt");
53 /*-------------------------------------------------------------------------*/
54 /* Constructor */
56 OSBShaderParameterMIntElement::OSBShaderParameterMIntElement(
57 OSBRootElement *root) :
59 Inherited(root, OSGOSBHeaderVersion200),
60 _value ( )
64 /*-------------------------------------------------------------------------*/
65 /* Destructor */
67 OSBShaderParameterMIntElement::~OSBShaderParameterMIntElement(void)
71 /*-------------------------------------------------------------------------*/
72 /* Reading */
74 void
75 OSBShaderParameterMIntElement::read(const std::string &typeName)
77 OSG_OSB_LOG(("OSBShaderParameterMIntElement::read: [%s]\n",
78 typeName.c_str()));
80 BinaryReadHandler *rh = editRoot()->getReadHandler();
82 UInt8 ptrTypeId;
83 UInt16 version;
85 rh->getValue(ptrTypeId);
86 rh->getValue(version );
88 OSG_OSB_LOG(("OSBShaderParameterMIntElement::read: version: [%u]\n",
89 version));
91 std::string fieldName;
92 std::string fieldTypeName;
93 UInt32 fieldSize;
94 PtrFieldListIt ptrFieldIt;
96 while(readFieldHeader("", fieldName, fieldTypeName, fieldSize))
98 if(fieldName == "name")
100 _name.copyFromBin(*rh);
102 else if(fieldName == "value")
104 _value.copyFromBin(*rh);
106 else
108 OSG_OSB_LOG(("Skipping [%d] bytes for field [%s]\n",
109 fieldSize, fieldName.c_str()));
110 rh->skip(fieldSize);
114 // no container is created for this element, which means the root does
115 // not automatically insert it into the IdElemMap - do it manually
116 editRoot()->editIdElemMap().insert(
117 OSBRootElement::IdElemMap::value_type(getFCIdFile(), this));
120 void
121 OSBShaderParameterMIntElement::postRead(void)
123 OSG_OSB_LOG(("OSBShaderParameterMIntElement::postRead:\n"));
126 /*-------------------------------------------------------------------------*/
127 /* Writing */
129 void
130 OSBShaderParameterMIntElement::preWrite(FieldContainer * const)
132 // This can not be called, ShaderParameterMInt does not exist
133 OSG_ASSERT(false);
136 void
137 OSBShaderParameterMIntElement::write(void)
139 // This can not be called, ShaderParameterMInt does not exist
140 OSG_ASSERT(false);
143 /*-------------------------------------------------------------------------*/
144 /* Access */
146 const MFInt32&
147 OSBShaderParameterMIntElement::getValue(void) const
149 return _value;
152 OSG_END_NAMESPACE