File: base-types.php

package info (click to toggle)
collada-dom 2.4.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 17,096 kB
  • sloc: cpp: 156,849; php: 4,567; makefile: 38; sh: 32; python: 14
file content (172 lines) | stat: -rw-r--r-- 3,257 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
/*
* Copyright 2006 Sony Computer Entertainment Inc.
*
* Licensed under the MIT Open Source License, for details please see license.txt or the website
* http://www.opensource.org/licenses/mit-license.php
*
*/ 

class _type
{
  var $type = array();
  
  function _type()
  {
    $this->type[] = "MotherOfAllTypes";
  }
  
  function isOfType( $type )
  {
    return( $type == $this->type[ count( $this->type ) - 1 ] );
  }
  
  function getType()
  {
    $type = "NULL";
    if ( count( $this->type ) > 0 ) { $type = $this->type[ 0 ]; }
    return $type;
  }
  
  function isAncestor( $type )
  {
    return in_array( $type, $this->type );
  }
}

class _typedData extends _type
{
  var $data;

  var $attributeMeta = array();
  var $attributes = array();
  
  function _typedData()
  {
    $this->type[] = "TypedData";
    parent::_type();
  }
  
  function _addAttribute( $name, $meta )
  {
    $this->attributeMeta[ $name ] = $meta;
  }
  
  function setAttribute( $name, $value )
  {
    // Make sure we know about the attribute before setting it
    if ( isset( $this->attributeMeta[ $name ] ) )
    {
      $this->attributes[ $name ] = $value;
    }
  }

  function getAttribute( $name )
  {
    $val = "";
    if ( isset( $this->attributeMeta[ $name ] ) && isset( $this->attributes[ $name ] ) ) { 
		$val = $this->attributes[ $name ]; 
	}
    return $val;
  }
  
  function & getAttributes()
  {
    return $this->attributes;
  }

  function set( & $buffer )
  {
    $this->data = $buffer;
  }
  
  function append( & $buffer )
  {
    $this->data .= $buffer;
  }
  
  function get()
  {
    return $this->data;
  }
}

class _elementSet extends _typedData
{
  var $elementMeta = array();
  var $elements = array();
  
  function _elementSet()
  {
    $this->_addAttribute( 'minOccurs', array( 'type' => 'xs:integer' ) );
    $this->setAttribute( 'minOccurs', '1' );
    $this->_addAttribute( 'maxOccurs', array( 'type' => 'xs:integer' ) );
    $this->setAttribute( 'maxOccurs', '1' );

    $this->type[] = "ElementSet";
    parent::_typedData();
  }
  
  function _addElement( $name, $attrs )
  {
    $this->elementMeta[ $name ] = $attrs;
  }

  function addElement( & $e )
  {
    if ( in_array( $e->getType(), array_keys( $this->elementMeta ) ) )
    {
      $this->elements[] = & $e;
    } else
    {
		print "Invalid element ". $e->getType() ."in ". $this->getType() ."\n";
      $this->log( "WARN: " . $e->getType() . " not a valid member of " . $this->getType() );
    }
  }
  
  function & getElements()
  {
    return $this->elements;
  }
  
  function & getElementsByType( $type )
  {
    $list = array();
    for( $i=0; $i<count( $this->elements ); $i++ )
    {
      if ( $this->elements[$i]->getType() == $type )
      {
        $list[] = & $this->elements[$i];
      }
    }
    return $list;
  }
  
  function setElement( $name, & $value )
  {
    $this->elements[ $name ] = $value;
  }
  
  function exists( $name )
  {
    return isset( $this->elements[ $name ] );
  }
  
  function delete( $name )
  {
    unset( $this->elements[ $name ] );
  }
  
  function _delete( $name )
  {
    $this->delete( $name );
    unset( $this->elementMeta[ $name ] );
  }
  
  function getCount()
  {
    return count( $this->elements );
  }
}

?>