File: OgOGroup.h

package info (click to toggle)
field3d 1.7.3-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,684 kB
  • sloc: cpp: 25,324; ansic: 2,594; python: 222; sh: 72; makefile: 26
file content (101 lines) | stat: -rw-r--r-- 2,894 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//----------------------------------------------------------------------------//

#ifndef _INCLUDED_Field3D_OgOGroup_H_
#define _INCLUDED_Field3D_OgOGroup_H_

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

#include "OgUtil.h"
#include "Exception.h"

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

#include "ns.h"

FIELD3D_NAMESPACE_OPEN

//----------------------------------------------------------------------------//
// OgOGroup
//----------------------------------------------------------------------------//

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

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

class OgOGroup : public Alembic::Util::noncopyable
{

public:

  // Ctor, dtor ----------------------------------------------------------------

  //! Constructs the root group in an Ogawa archive
  OgOGroup(Alembic::Ogawa::OArchive &archive)
    : m_name("f3droot") 
  {
    // Reference the root group
    m_group = archive.getGroup();
    // Base data sets
    addBaseData();
  }

  //! Constructs a group as a child to an existing group.
  OgOGroup(OgOGroup &parent, const std::string &name)
    : m_name(name)
  {
    // Make sure there is no '/' in the name
    if (name.find("/") != std::string::npos) {
      throw Field3D::Exc::OgOGroupException("'/' character in group name.");
    }
    // Construct the group
    m_group = parent.m_group->addGroup();
    // Base data sets
    addBaseData();
  }

  // Main methods --------------------------------------------------------------

  //! Adds an ogawa-level subgroup. Called from OgOAttribute and OgODataset.
  Alembic::Ogawa::OGroupPtr addSubGroup() 
  {
    return m_group->addGroup();
  }

private:

  // Utility methods -----------------------------------------------------------

  void addBaseData()
  {
    // Index 0 is the name
    if (!writeString(m_group, m_name)) {
      throw Field3D::Exc::OgOGroupException("Failed to write group name.");
    }
    // Index 1 is the type
    if (!writeData(m_group, F3DGroupType)) {
      throw Field3D::Exc::OgOGroupException("Failed to write group type.");
    }
  }

  // Data members --------------------------------------------------------------

  //! Pointer to the enclosing Ogawa-level group.
  Alembic::Ogawa::OGroupPtr m_group;
  //! Name of the curren
  std::string               m_name;
};

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

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

#endif // include guard

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