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