root/OpenSceneGraph/trunk/src/osgPlugins/ive/ShapeAttributeList.cpp @ 13041

Revision 13041, 2.9 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
Line 
1/**********************************************************************
2 *
3 *    FILE:           ShapeAttributeList.cpp
4 *
5 *    DESCRIPTION:    Read/Write osgSim::ShapeAttributeList in binary
6 *                    format to disk.
7 *
8 *    CREATED BY:     John Vidar Larring
9 *
10 *    HISTORY:        Created 25.8.2008
11 *
12 **********************************************************************/
13
14#include "Exception.h"
15#include "ShapeAttributeList.h"
16
17using namespace ive;
18
19void ShapeAttributeList::write(DataOutputStream* out)
20{
21
22    // Write ShapeAttributeList's identification.
23    out->writeInt(IVESHAPEATTRIBUTELIST);
24
25    // Write ShapeAttributeList's properties.
26
27    // Write size of list
28    out->writeUInt(size());
29
30    // Write elements of the list
31    for (const_iterator it = begin(); it != end(); it++)
32    {
33        write(out, *it);
34    }
35}
36
37void ShapeAttributeList::read(DataInputStream* in)
38{
39    // Peek on ShapeAttributeList's identification.
40    int id = in->peekInt();
41    if(id == IVESHAPEATTRIBUTELIST){
42        // Read ShapeAttributeList's identification.
43        id = in->readInt();
44
45        // Read ShapeAttributeList's properties
46
47        // Read size of the list
48        unsigned int count = in->readUInt();
49
50        resize(count);
51
52        // Read elements of the list
53        for (unsigned int i=0; i < count; i++)
54        {
55            read(in, (*this)[i]);
56        }
57    }
58    else{
59        in_THROW_EXCEPTION("ShapeAttributeList::read(): Expected ShapeAttributeList identification.");
60    }
61}
62
63void ShapeAttributeList::write(DataOutputStream* out, const osgSim::ShapeAttribute& sa)
64{
65    // Write name
66    out->writeString(sa.getName());
67
68    // Write datatype
69    osgSim::ShapeAttribute::Type type = sa.getType();
70    out->writeInt((int)type);
71
72    // Write data
73    switch (type)
74    {
75    case osgSim::ShapeAttribute::INTEGER:
76        out->writeInt(sa.getInt());
77        break;
78    case osgSim::ShapeAttribute::DOUBLE:
79        out->writeDouble(sa.getDouble());
80        break;
81    case osgSim::ShapeAttribute::STRING:
82        out->writeBool(sa.getString() != 0);
83        if (sa.getString()) out->writeString(std::string(sa.getString()));
84        break;
85    default:
86        // Ignore Unknown data type
87        break;
88    }
89}
90
91void ShapeAttributeList::read(DataInputStream* in, osgSim::ShapeAttribute& sa)
92{
93    // Read name
94    sa.setName(in->readString());
95
96    // Read type
97    int type = in->readInt();
98
99    // Read data
100    switch (type)
101    {
102        case osgSim::ShapeAttribute::INTEGER:
103            sa.setValue(in->readInt());
104            break;
105        case osgSim::ShapeAttribute::DOUBLE:
106            sa.setValue(in->readDouble());
107            break;
108        case osgSim::ShapeAttribute::STRING:
109            if (in->readBool())
110                sa.setValue(in->readString().c_str());
111            else
112                sa.setValue((char*)0);
113            break;
114        default:
115            // Ignore Unknown data type
116            break;
117    }
118}
Note: See TracBrowser for help on using the browser.