File: OgOAttribute.h

package info (click to toggle)
field3d 1.7.3-6
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,684 kB
  • sloc: cpp: 25,324; ansic: 2,594; python: 222; sh: 72; makefile: 26
file content (78 lines) | stat: -rw-r--r-- 2,425 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
//----------------------------------------------------------------------------//

#ifndef _INCLUDED_Field3D_OgOAttribute_H_
#define _INCLUDED_Field3D_OgOAttribute_H_

//----------------------------------------------------------------------------//
// Includes
//----------------------------------------------------------------------------//

#include "OgUtil.h"
#include "OgOGroup.h"

//----------------------------------------------------------------------------//

#include "ns.h"

FIELD3D_NAMESPACE_OPEN

//----------------------------------------------------------------------------//
// OgOAttribute
//----------------------------------------------------------------------------//

/*! \class OgOAttribute
  Ogawa output attribute. Writes a variable as an attribute into an F3D-style
  Ogawa file.
*/

//----------------------------------------------------------------------------//

template <typename T>
class OgOAttribute
{

public:

  // Typedefs ------------------------------------------------------------------

  typedef T value_type;

  // Ctors, dtor ---------------------------------------------------------------

  //! Creates the attribute and writes the data.
  OgOAttribute(OgOGroup &parent, const std::string &name, const T &value)
  {
    using Field3D::Exc::OgOAttributeException;

    // Create a group to store the attribute data
    Alembic::Ogawa::OGroupPtr group = parent.addSubGroup();
    // Index 0 is the name
    if (!writeString(group, name)) {
      throw OgOAttributeException("Couldn't write attribute name for " + name);
    }
    // Index 1 is the type
    if (!writeData(group, F3DAttributeType)) {
      throw OgOAttributeException("Couldn't write attribute group type for " + 
                                  name);
    }
    // Index 2 is the data type
    if (!writeDataType<T>(group)) {
      throw OgOAttributeException("Couldn't write attribute data type for " + 
                                  name);
    }
    // Index 3 is the data
    if (!writeData<T>(group, value)) {
      throw OgOAttributeException("Couldn't write attribute data for " + name);
    }
  }
};

//----------------------------------------------------------------------------//
  
FIELD3D_NAMESPACE_HEADER_CLOSE

//----------------------------------------------------------------------------//

#endif // include guard

//----------------------------------------------------------------------------//