/[suikacvs]/messaging/manakai/lib/Message/Util/ManakaiNode.dis
Suika

Contents of /messaging/manakai/lib/Message/Util/ManakaiNode.dis

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.20 - (hide annotations) (download)
Sat Sep 24 13:50:57 2005 UTC (19 years, 9 months ago) by wakaba
Branch: MAIN
Changes since 1.19: +47 -22 lines
++ manakai/lib/Message/Util/ChangeLog	24 Sep 2005 13:50:35 -0000
	* ManakaiNode.dis (NodeStem): Property value "mn:treeID"
	has changed to scalar reference.

2005-09-24  Wakaba  <wakaba@suika.fam.cx>

1 wakaba 1.1 Module:
2     @QName:
3     Util:ManakaiNode
4     @FullName:
5     @@lang: en
6     @@@:
7     Manakai Generic Node Implementation
8     @Namespace:
9     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ManakaiNode#
10    
11     @Description:
12     @@lang:en
13     @@@:
14     The <Module::Util:ManakaiNode> module provides a basic
15     implementation for glaph (perhaps tree) structures.
16    
17 wakaba 1.18 @DISCore:author: DISCore|Wakaba
18 wakaba 1.1 @License:
19     license:Perl+MPL
20     @Date:
21     @@@:
22 wakaba 1.20 $Date: 2005/09/24 11:57:25 $
23 wakaba 1.1 @@ContentType:
24     dis:Date.RCS
25    
26     @Require:
27     @@Module:
28 wakaba 1.4 @@@QName:
29     DISlib:DISPerl
30 wakaba 1.1 @@@WithFor:
31     ManakaiDOM:all
32 wakaba 1.2 @@Module:
33 wakaba 1.16 @@@QName: Util|ManakaiNode
34 wakaba 1.2 @@@WithFor:
35     ManakaiDOM:Perl
36    
37     @DefaultFor:
38     ManakaiDOM:Perl
39 wakaba 1.1
40     Namespace:
41 wakaba 1.13 @DIS:
42     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/DIS#
43 wakaba 1.1 @dis:
44     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#dis--
45     @dis2pm:
46     http://suika.fam.cx/~wakaba/archive/2004/11/8/dis2pm#
47 wakaba 1.4 @DISlib:
48     http://suika.fam.cx/~wakaba/archive/2004/dis/
49 wakaba 1.13 @doc:
50     http://suika.fam.cx/~wakaba/archive/2005/7/tutorial#
51 wakaba 1.1 @lang:
52     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#
53     @license:
54     http://suika.fam.cx/~wakaba/archive/2004/8/18/license#
55     @ManakaiDOM:
56     http://suika.fam.cx/~wakaba/archive/2004/8/18/manakai-dom#
57 wakaba 1.10 @mn:
58     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/ManakaiNode#
59 wakaba 1.1 @Perl:
60     http://suika.fam.cx/~wakaba/archive/2004/8/18/lang#Perl--
61     @rdf:
62     http://www.w3.org/1999/02/22-rdf-syntax-ns#
63     @rdfs:
64     http://www.w3.org/2000/01/rdf-schema#
65     @TreeCore:\
66     @Util:
67     http://suika.fam.cx/~wakaba/archive/2005/manakai/Util/
68    
69     ResourceDef:
70     @QName:
71     Util:
72     @rdf:type:
73     dis:ModuleGroup
74     @FullName:
75     @@lang:en
76     @@@:
77     The manakai support modules
78 wakaba 1.17 @DISPerl:packageName:
79 wakaba 1.14 Message::Util::
80 wakaba 1.17 @DISPerl:interfacePackageName:
81     Message::Util::IF::
82 wakaba 1.13
83 wakaba 1.1 ## -- Internal node object
84    
85     ClassDef:
86 wakaba 1.10 @resourceFor: ForFull
87     @resourceFor: ForCompact
88     @resourceFor:
89     ManakaiDOM:ForIF
90    
91     @QName:
92     @@@: NodeStem
93     @@ForCheck:
94     ManakaiDOM:ForIF
95    
96 wakaba 1.1 @QName:
97 wakaba 1.10 @@@:
98     ManakaiDOM:ManakaiDOMNodeObject
99     @@ForCheck: ForFull
100    
101     @QName:
102     @@@: ManakaiNodeStem
103     @@ForCheck: ForCompact
104    
105     @Implement:
106     @@@: NodeStem
107     @@ForCheck: ForFull
108    
109     @Implement:
110     @@@: NodeStem
111     @@ForCheck: ForCompact
112    
113 wakaba 1.1 @Description:
114     @@lang:en
115     @@@:
116     Internal (actual) node objects that is accessed via
117     <Class::ManakaiDOM:ManakaiDOMNodeReference> objects referring it.
118     @ImplNote:
119     @@lang:en
120     @@@:
121     No public interface should be defined for any class inheriting
122     this class - applications should access to nodes only via
123     <Class::ManakaiDOM:ManakaiDOMNodeReference> objects.
124     @ImplNote:
125 wakaba 1.13 @@ForCheck: ManakaiDOM|ForClass
126 wakaba 1.1 @@lang:en
127     @@@:
128 wakaba 1.13 A <Class::> object is a blessed hash
129 wakaba 1.1 reference. Each hash key and value pair is called as a
130     <DFN::property>. Currently, several core properties
131 wakaba 1.13 are defined as listed below. Applications of this class,
132     such as <Class::DOMCore:ManakaiDOMNode::ManakaiDOM:all>,
133     defines additional properties for their own purpose and scope.
134 wakaba 1.1 \
135 wakaba 1.13 {doc:fig:: <doc:caption::Core node properties>
136    
137     {doc:figBody::
138 wakaba 1.1 \
139     - <CODE::TreeCore:origin>::: An array reference, containing
140     hash key names of <DFN::origin>
141     properties for this node.
142     \
143 wakaba 1.3 - <CODE::TreeCore:subnode0>::: An array reference, containing
144     hash key names of <DFN::subnode>
145     properties for this node.
146     \
147 wakaba 1.1 - <CODE::TreeCore:subnode>::: An array reference, containing
148 wakaba 1.3 hash key names of <DFN::subnode> list
149 wakaba 1.1 properties for this node.
150     \
151     - <CODE::TreeCore:subnode2>::: An array reference, containing
152 wakaba 1.3 hash key names of <DFN::subnode> (two steps) list
153 wakaba 1.1 properties for this node.
154     \
155     - <CODE::TreeCore:irefnode>::: An array reference, containing
156     hash key names of <DFN::irefnode>
157     properties for this node.
158     \
159     - <CODE::TreeCore:anydata>::: An array reference, containing
160 wakaba 1.3 hash key names of <DFN::anydata> list
161     properties for this node.
162 wakaba 1.1 \
163     - <CODE::TreeCore:anydata2>::: An array reference, containing
164 wakaba 1.3 hash key names of <DFN::anydata> (two steps) list properties
165 wakaba 1.1 for this node.
166 wakaba 1.13 }
167 wakaba 1.1 }
168    
169     @IntMethod:
170     @@Name: new
171     @@Description:
172     @@@lang:en
173     @@@@:
174     Constructs a new instance of
175     <Class::ManakaiDOM:ManakaiDOMNodeObject> and returns it.
176     @@Return:
177 wakaba 1.10 @@@Type: NodeStem
178 wakaba 1.1 @@@Description:
179     @@@@lang:en
180     @@@@@:
181     The newly created <Class::ManakaiDOM:ManakaiDOMNodeObject> instance.
182 wakaba 1.7 @@@PerlDef:
183 wakaba 1.20 @@@@ForCheck: ForFull
184     @@@@@:
185 wakaba 1.1 $r = bless {
186     <Q::TreeCore:origin> => [],
187 wakaba 1.3 <Q::TreeCore:subnode0> => [],
188 wakaba 1.1 <Q::TreeCore:subnode> => [],
189     <Q::TreeCore:subnode2> => [],
190     <Q::TreeCore:irefnode> => [],
191     <Q::TreeCore:anydata> => [],
192     <Q::TreeCore:anydata2> => [],
193 wakaba 1.19 <H::mn:rc> => 0,
194     <H::mn:treeID> => <Code::ManakaiDOM:generateUniqueID>,
195     <H::mn:nodeID> => <Code::ManakaiDOM:generateUniqueID>,
196 wakaba 1.1 }, ref $self || $self;
197 wakaba 1.20 @@@PerlDef:
198     @@@@ForCheck: ForCompact
199     @@@@@:
200     $r = bless {
201     <Q::TreeCore:origin> => [],
202     <Q::TreeCore:subnode0> => [],
203     <Q::TreeCore:subnode> => [],
204     <Q::TreeCore:subnode2> => [],
205     <Q::TreeCore:irefnode> => [],
206     <Q::TreeCore:anydata> => [],
207     <Q::TreeCore:anydata2> => [],
208     <H::mn:rc> => 0,
209     <H::mn:treeID> => \ (<Code::ManakaiDOM:generateUniqueID>),
210     <H::mn:nodeID> => <Code::ManakaiDOM:generateUniqueID>,
211     }, ref $self || $self;
212 wakaba 1.10
213 wakaba 1.1 @IntMethod:
214     @@Name: newReference
215     @@Description:
216     @@@lang:en
217     @@@@:
218     Creates a new reference to this node and returns it.
219 wakaba 1.6 @@DISCore:isDeprecated:
220     @@@@:1
221     @@@DISCore:alt: getNewReference
222 wakaba 1.10 @@ForCheck: ForFull
223 wakaba 1.1 @@Param:
224     @@@Name: class
225     @@@Type:
226 wakaba 1.7 Perl:package-name::ManakaiDOM:all
227 wakaba 1.1 @@@Description:
228     @@@@lang:en
229     @@@@@:
230     A Perl class package name with which the newly created
231     reference is blessed. The <P::class> class must be a
232     subclass of <Class::ManakaiDOM:ManakaiDOM:ManakaiDOMNodeReference>.
233     @@Return:
234     @@@Type:
235     ManakaiDOM:ManakaiDOMNodeReference
236     @@@Description:
237     @@@@lang:en
238     @@@@@:
239     The newly created node reference.
240     @@@PerlDef:
241     $r = bless {
242 wakaba 1.19 <H::mn:node> => $self,
243 wakaba 1.7 }, ref $class ? ref $class : defined $class ? $class :
244 wakaba 1.1 <ClassName::ManakaiDOM:ManakaiDOMNodeReference>;
245 wakaba 1.19 $self->{<H::mn:rc>}++;
246 wakaba 1.6
247     @ResourceDef:
248     @@QName: getNewReference
249     @@rdf:type:
250     dis2pm:BlockCode
251 wakaba 1.20 @@ForCheck: ForCompact
252 wakaba 1.6 @@Description:
253     @@@lang:en
254     @@@@:
255     Creates a new node reference object.
256     @@ResourceDef:
257     @@@rdf:type:
258     DISPerl:CodeParameter
259     @@@Name: $object
260 wakaba 1.10 @@@Type: NodeStem
261 wakaba 1.6 @@@In:1
262     @@@enDesc:
263     A node object for which a reference is created.
264     @@@DISPerl:paramStyle: var
265     @@ResourceDef:
266     @@@rdf:type:
267     DISPerl:CodeParameter
268     @@@Name: $ref
269 wakaba 1.10 @@@Type: NodeRef
270 wakaba 1.6 @@@Out:1
271     @@@enDesc:
272     A node reference for <P::$object>. It may or may not
273     be same as <P::$object>.
274     @@@DISPerl:paramStyle: var
275     @@ResourceDef:
276     @@@rdf:type:
277     DISPerl:CodeParameter
278     @@@Name: $class
279     @@@Type:
280     Perl:package-name::ManakaiDOM:all
281     @@@enDesc:
282     A package name with which <P::$ref> is blessed.
283     @@@In:1
284     @@@DISPerl:paramStyle: any
285     @@PerlDef:
286 wakaba 1.19 $object->{<H::mn:rc>}++;
287 wakaba 1.6 $ref = bless {
288 wakaba 1.19 <H::mn:node> => $object,
289 wakaba 1.6 }, $class;
290    
291     @ResourceDef:
292     @@QName: getWeakReference
293     @@rdf:type:
294     dis2pm:BlockCode
295 wakaba 1.20 @@ForCheck: ForCompact
296 wakaba 1.6 @@Description:
297     @@@lang:en
298     @@@@:
299     Creates a new weak node reference object.
300     \
301     The weak node reference is actually a node reference
302     except that this code fragment does not increment
303     the reference count of the object. When all non-weak
304     references to the object are destructed, then
305     the object is destructed and any operation via
306     weak references will lead unexpected result.
307     \
308     {NOTE:: It is intended that internal code creates a weak reference
309     so that it gets access to public interface.
310     \
311     }
312     @@ResourceDef:
313     @@@rdf:type:
314     DISPerl:CodeParameter
315     @@@Name: $object
316 wakaba 1.10 @@@Type: NodeStem
317 wakaba 1.6 @@@In:1
318     @@@enDesc:
319     A node object for which a reference is created.
320     @@@DISPerl:paramStyle: var
321     @@ResourceDef:
322     @@@rdf:type:
323     DISPerl:CodeParameter
324     @@@Name: $ref
325 wakaba 1.10 @@@Type: NodeRef
326 wakaba 1.6 @@@Out:1
327     @@@enDesc:
328     A node reference for <P::$object>. It may or may not
329     be same as <P::$object>.
330     @@@DISPerl:paramStyle: var
331     @@ResourceDef:
332     @@@rdf:type:
333     DISPerl:CodeParameter
334     @@@Name: $class
335     @@@Type:
336     Perl:package-name::ManakaiDOM:all
337     @@@enDesc:
338     A package name with which <P::$ref> is blessed.
339     @@@In:1
340     @@@DISPerl:paramStyle: any
341     @@PerlDef:
342     $ref = bless {
343 wakaba 1.19 <H::mn:node> => $object,
344     <H::mn:isWeak> => true,
345 wakaba 1.8 }, $class;
346    
347     @ResourceDef:
348     @@QName: getWeakRef
349     @@rdf:type:
350     dis2pm:InlineCode
351 wakaba 1.10 @@ForCheck: ForFull
352 wakaba 1.8 @@Description:
353     @@@lang:en
354     @@@@:
355     Creates a new weak node reference object.
356     \
357     The weak node reference is actually a node reference
358     except that this code fragment does not increment
359     the reference count of the object. When all non-weak
360     references to the object are destructed, then
361     the object is destructed and any operation via
362     weak references will lead unexpected result.
363     \
364     {NOTE:: It is intended that internal code creates a weak reference
365     so that it gets access to public interface.
366     \
367     }
368     @@ResourceDef:
369     @@@rdf:type:
370     DISPerl:CodeParameter
371     @@@Name: $object
372 wakaba 1.10 @@@Type: NodeStem
373 wakaba 1.8 @@@In:1
374     @@@enDesc:
375     A node object for which a reference is created.
376     @@@DISPerl:paramStyle: var
377     @@ResourceDef:
378     @@@rdf:type:
379     DISPerl:CodeParameter
380     @@@Name: $class
381     @@@Type:
382     Perl:package-name::ManakaiDOM:all
383     @@@enDesc:
384     A package name with which <P::$ref> is blessed.
385     @@@In:1
386     @@@DISPerl:paramStyle: any
387     @@PerlDef:
388 wakaba 1.9 (bless {
389 wakaba 1.19 <H::mn:node> => $object,
390     <H::mn:isWeak> => true,
391 wakaba 1.9 }, $class)
392 wakaba 1.6
393 wakaba 1.1 @IntMethod:
394     @@Name: isExternallyReferred
395     @@Description:
396     @@@lang:en
397     @@@@:
398     Checks whether the tree containing this node has been referred
399     from the outside of the tree or not.
400     @@Return:
401     @@@Type:
402 wakaba 1.7 DISPerl:Boolean::ManakaiDOM:all
403 wakaba 1.1 @@@InCase:
404 wakaba 1.15 @@@@Value:
405     @@@@@@:1
406     @@@@@ContentType: DISCore|Boolean
407 wakaba 1.1 @@@@Description:
408     @@@@@lang:en
409     @@@@@@:
410     There is one or more nodes in the tree that has been
411     referred via <Class::ManakaiDOM:ManakaiDOMNodeReference> objects.
412     @@@InCase:
413 wakaba 1.15 @@@@Value:
414     @@@@@@:0
415     @@@@@ContentType: DISCore|Boolean
416 wakaba 1.1 @@@@Description:
417     @@@@@lang:en
418     @@@@@@: No external reference found.
419     @@@PerlDef:
420 wakaba 1.10 @@@@ForCheck: ForFull
421     @@@@@:
422 wakaba 1.19 if ($self->{<H::mn:rc>}) {
423 wakaba 1.1 $r = true;
424     } else {
425     my @node = ($self);
426     my %checked;
427 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
428 wakaba 1.9 next unless UNIVERSAL::isa ($node,
429     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
430 wakaba 1.19 if ($node->{<H::mn:rc>}) {
431 wakaba 1.1 $r = true;
432     last NODES;
433 wakaba 1.19 } elsif ($checked{$node->{<H::mn:nodeID>}}) {
434 wakaba 1.1 next NODES;
435     }
436     my @n;
437 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
438     if (ref $node->{$p} eq 'ARRAY') {
439     push @n, @{$node->{$p}};
440     } elsif (ref $node->{$p} eq 'HASH') {
441     push @n, values %{$node->{$p}};
442 wakaba 1.1 }
443     }
444 wakaba 1.3 for my $p (@n,
445     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
446     if (ref $p eq 'ARRAY') {
447     push @node, @$p;
448     } elsif (ref $p eq 'HASH') {
449     push @node, values %$p;
450 wakaba 1.1 }
451     }
452 wakaba 1.6 for my $p (@{$node->{<Q::TreeCore:origin>}}) {
453     unshift @node, $node->{$p} if $node->{$p};
454     ## NOTE: Puts the top of the list,
455     ## since upper-level nodes are expected to be referred
456     ## more than lower-levels.
457     }
458     for my $p (@{$node->{<Q::TreeCore:subnode0>}}) {
459 wakaba 1.3 push @node, $node->{$p} if $node->{$p};
460 wakaba 1.1 }
461 wakaba 1.19 $checked{$node->{<H::mn:nodeID>}} = true;
462 wakaba 1.1 }
463     }
464 wakaba 1.10 @@@PerlDef:
465     @@@@ForCheck: ForCompact
466     @@@@@:
467 wakaba 1.19 if ($self->{<H::mn:rc>}) {
468 wakaba 1.10 $r = true;
469     } else {
470     my @node = ($self);
471     my %checked;
472 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
473 wakaba 1.10 next unless ref $node;
474 wakaba 1.19 if ($node->{<H::mn:rc>}) {
475 wakaba 1.10 $r = true;
476     last NODES;
477 wakaba 1.19 } elsif ($checked{$node->{<H::mn:nodeID>}}) {
478 wakaba 1.10 next NODES;
479     }
480     my @n;
481     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
482     if (ref $node->{$p} eq 'ARRAY') {
483     push @n, @{$node->{$p}};
484     } elsif (ref $node->{$p} eq 'HASH') {
485     push @n, values %{$node->{$p}};
486     }
487     }
488     for my $p (@n,
489     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
490     if (ref $p eq 'ARRAY') {
491     push @node, @$p;
492     } elsif (ref $p eq 'HASH') {
493     push @node, values %$p;
494     }
495     }
496     for my $p (@{$node->{<Q::TreeCore:origin>}}) {
497     unshift @node, $node->{$p} if $node->{$p};
498     ## NOTE: Puts the top of the list,
499     ## since upper-level nodes are expected to be referred
500     ## more than lower-levels.
501     }
502     for my $p (@{$node->{<Q::TreeCore:subnode0>}}) {
503     push @node, $node->{$p} if $node->{$p};
504     }
505 wakaba 1.19 $checked{$node->{<H::mn:nodeID>}} = 1;
506 wakaba 1.10 }
507     }
508 wakaba 1.1
509     @IntMethod:
510     @@Name: destroy
511     @@Description:
512     @@@lang:en
513     @@@@:
514     Destructs the tree containing this node.
515     @@Return:
516     @@@PerlDef:
517 wakaba 1.10 @@@@ForCheck: ForFull
518     @@@@@:
519 wakaba 1.1 my @node = ($self);
520 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
521 wakaba 1.1 my @n;
522 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
523     if (ref $node->{$p} eq 'ARRAY') {
524     push @n, @{$node->{$p}};
525     } elsif (ref $node->{$p} eq 'HASH') {
526     push @n, values %{$node->{$p}};
527 wakaba 1.1 }
528     }
529 wakaba 1.3 for my $p (@n,
530     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
531     if (ref $p eq 'ARRAY') {
532 wakaba 1.10 push @node, grep {UNIVERSAL::isa ($_,
533     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
534 wakaba 1.19 and defined $_->{<H::mn:nodeID>}} @$p;
535 wakaba 1.3 } elsif (ref $p eq 'HASH') {
536 wakaba 1.10 push @node, grep {UNIVERSAL::isa ($_,
537     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
538 wakaba 1.19 and defined $_->{<H::mn:nodeID>}}
539 wakaba 1.3 values %$p;
540 wakaba 1.1 }
541     }
542 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
543     \ @{$node->{<Q::TreeCore:subnode0>}}) {
544     push @node, $node->{$p}
545     if defined $node->{$p} and
546 wakaba 1.19 defined $node->{$p}->{<H::mn:nodeID>};
547 wakaba 1.1 }
548     %$node = ();
549     }
550 wakaba 1.10 @@@PerlDef:
551     @@@@ForCheck: ForCompact
552     @@@@@:
553     my @node = ($self);
554 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
555 wakaba 1.19 next unless ref $node and defined $node->{<H::mn:nodeID>};
556 wakaba 1.10 my @n;
557     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
558     if (ref $node->{$p} eq 'ARRAY') {
559     push @n, @{$node->{$p}};
560     } elsif (ref $node->{$p} eq 'HASH') {
561     push @n, values %{$node->{$p}};
562     }
563     }
564     for my $p (@n,
565     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
566     if (ref $p eq 'ARRAY') {
567     push @node, @$p;
568     } elsif (ref $p eq 'HASH') {
569     push @node, values %$p;
570     }
571     }
572     for my $p (@{$node->{<Q::TreeCore:origin>}},
573     \ @{$node->{<Q::TreeCore:subnode0>}}) {
574     push @node, $node->{$p};
575     }
576     %$node = ();
577     }
578 wakaba 1.1 @@ImplNote:
579     @@@lang:en
580     @@@@:
581     This method is different from Perl <Perl::DESTROY> special
582     purpose method.
583     \
584     An <QUOTE::uninitialized> warning in this method might mean
585     some method puts an <Perl::undef> into a list of nodes.
586    
587     @IntMethod:
588     @@Name: importTree
589     @@Description:
590     @@@lang:en
591     @@@@:
592     Changes the tree identifier of the nodes belong to another tree
593     to be same as this node's tree identifier.
594     @@Param:
595     @@@Name: node
596     @@@Type:
597     ManakaiDOM:ManakaiDOMNodeObject
598     @@@Description:
599     @@@@lang:en
600     @@@@@:
601     Any node from the tree to change its identifier.
602     @@Return:
603     @@@PerlDef:
604 wakaba 1.10 @@@@ForCheck: ForFull
605     @@@@@:
606 wakaba 1.19 unless ($node->{<H::mn:treeID>} eq
607     $self->{<H::mn:treeID>}) {
608 wakaba 1.1 my @node = ($node);
609 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
610 wakaba 1.10 next unless UNIVERSAL::isa ($node,
611     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
612 wakaba 1.1 my @n;
613 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
614     if (ref $node->{$p} eq 'ARRAY') {
615     push @n, @{$node->{$p}};
616     } elsif (ref $node->{$p} eq 'HASH') {
617     push @n, values %{$node->{$p}};
618 wakaba 1.1 }
619     }
620 wakaba 1.3 for my $p (@n,
621     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
622     if (ref $p eq 'ARRAY') {
623 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
624     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
625 wakaba 1.19 and $_->{<H::mn:treeID>} ne
626     $self->{<H::mn:treeID>}} @$p;
627 wakaba 1.3 } elsif (ref $p eq 'HASH') {
628 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
629     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
630 wakaba 1.19 and $_->{<H::mn:treeID>} ne
631     $self->{<H::mn:treeID>}}
632 wakaba 1.3 values %$p;
633 wakaba 1.1 }
634     }
635 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
636     \ @{$node->{<Q::TreeCore:subnode0>}}) {
637     push @node, $node->{$p}
638     if defined $node->{$p} and
639 wakaba 1.19 $node->{$p}->{<H::mn:treeID>} ne
640     $self->{<H::mn:treeID>};
641 wakaba 1.1 }
642 wakaba 1.19 $node->{<H::mn:treeID>} = $self->{<H::mn:treeID>};
643 wakaba 1.1 }
644     }
645 wakaba 1.10 @@@PerlDef:
646     @@@@ForCheck: ForCompact
647     @@@@@:
648     my @node = ($node);
649 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
650 wakaba 1.10 next unless ref $node;
651 wakaba 1.20 next if ${$node->{<H::mn:treeID>}} eq
652     ${$self->{<H::mn:treeID>}};
653 wakaba 1.10 my @n;
654     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
655     if (ref $node->{$p} eq 'ARRAY') {
656     push @n, @{$node->{$p}};
657     } elsif (ref $node->{$p} eq 'HASH') {
658     push @n, values %{$node->{$p}};
659     }
660     }
661     for my $p (@n,
662     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
663     if (ref $p eq 'ARRAY') {
664     push @node, @$p;
665     } elsif (ref $p eq 'HASH') {
666     push @node, values %$p;
667     }
668     }
669     for my $p (@{$node->{<Q::TreeCore:origin>}},
670     \ @{$node->{<Q::TreeCore:subnode0>}}) {
671     push @node, $node->{$p};
672     }
673 wakaba 1.19 $node->{<H::mn:treeID>} = $self->{<H::mn:treeID>};
674 wakaba 1.10 }
675 wakaba 1.1
676     @IntMethod:
677     @@Name: changeTreeID
678     @@Description:
679     @@@lang:en
680     @@@@:
681     Changes tree identifier of all nodes traversable from this node.
682     @@Param:
683     @@@Name: treeID
684     @@@Type:
685 wakaba 1.7 DISPerl:String::ManakaiDOM:all
686 wakaba 1.1 @@@Description:
687     @@@@lang:en
688     @@@@@:
689     The new tree identifier.
690 wakaba 1.20 @@@InCase:
691     @@@@Type: DISPerl|SCALAR
692     @@@@enDesc:
693     A reference to the new tree identifier.
694     The tree will reference the identifier as it.
695 wakaba 1.1 @@Return:
696     @@@PerlDef:
697 wakaba 1.10 @@@@ForCheck: ForFull
698     @@@@@:
699 wakaba 1.19 unless ($self->{<H::mn:treeID>} eq $treeID) {
700 wakaba 1.1 my @node = ($self);
701 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
702 wakaba 1.9 next unless UNIVERSAL::isa ($node,
703     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>);
704 wakaba 1.1 my @n;
705 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
706     if (ref $node->{$p} eq 'ARRAY') {
707     push @n, @{$node->{$p}};
708     } elsif (ref $node->{$p} eq 'HASH') {
709     push @n, values %{$node->{$p}};
710 wakaba 1.1 }
711     }
712 wakaba 1.3 for my $p (@n,
713     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
714     if (ref $p eq 'ARRAY') {
715 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
716     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
717 wakaba 1.5 and
718 wakaba 1.19 $_->{<H::mn:treeID>} ne $treeID} @$p;
719 wakaba 1.3 } elsif (ref $p eq 'HASH') {
720 wakaba 1.9 push @node, grep {UNIVERSAL::isa ($_,
721     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>)
722 wakaba 1.19 and $_->{<H::mn:treeID>} ne $treeID}
723 wakaba 1.3 values %$p;
724 wakaba 1.1 }
725     }
726 wakaba 1.3 for my $p (@{$node->{<Q::TreeCore:origin>}},
727     \ @{$node->{<Q::TreeCore:subnode0>}}) {
728     push @node, $node->{$p}
729     if defined $node->{$p} and
730 wakaba 1.19 $node->{$p}->{<H::mn:treeID>} ne $treeID;
731 wakaba 1.1 }
732 wakaba 1.19 $node->{<H::mn:treeID>} = $treeID;
733 wakaba 1.1 }
734     }
735     @@@PerlDef:
736 wakaba 1.10 @@@@ForCheck: ForCompact
737     @@@@@:
738 wakaba 1.20 my $tid = ref $treeID ? $treeID : \$treeID;
739 wakaba 1.10 my @node = ($self);
740 wakaba 1.12 NODES: while (defined (my $node = shift @node)) {
741 wakaba 1.10 next unless ref $node;
742 wakaba 1.20 next if ${$node->{<H::mn:treeID>}} eq $$tid;
743 wakaba 1.10 my @n;
744     for my $p (@{$node->{<Q::TreeCore:subnode2>}}) {
745     if (ref $node->{$p} eq 'ARRAY') {
746     push @n, @{$node->{$p}};
747     } elsif (ref $node->{$p} eq 'HASH') {
748     push @n, values %{$node->{$p}};
749     }
750     }
751     for my $p (@n,
752     map {$node->{$_}} @{$node->{<Q::TreeCore:subnode>}}) {
753     if (ref $p eq 'ARRAY') {
754     push @node, @$p;
755     } elsif (ref $p eq 'HASH') {
756     push @node, values %$p;
757     }
758     }
759     for my $p (@{$node->{<Q::TreeCore:origin>}},
760     \ @{$node->{<Q::TreeCore:subnode0>}}) {
761     push @node, $node->{$p};
762     }
763 wakaba 1.20 $node->{<H::mn:treeID>} = $tid;
764 wakaba 1.1 }
765    
766     @IntMethod:
767     @@Name: isSameNode
768     @@Description:
769     @@@lang:en
770     @@@@:
771     Returns whether a node is the same as this node or not.
772     \
773     {NOTE:: The sameness is different from the equality;
774     two nodes are same iff they are same hash reference.
775     \
776     }
777     @@Operator:
778     @@@ContentType:
779     lang:Perl
780     @@@@: eq
781     @@Param:
782     @@@Name: node
783 wakaba 1.10 @@@Type: NodeStem
784 wakaba 1.1 @@@Description:
785     @@@@lang:en
786     @@@@@:
787     A node to compare with.
788     @@Return:
789     @@@Type:
790 wakaba 1.7 DISPerl:Boolean::ManakaiDOM:all
791 wakaba 1.1 @@@Description:
792     @@@@lang:en
793     @@@@@: Whether the two nodes are same or not.
794     @@@PerlDef:
795 wakaba 1.10 @@@@ForCheck: ForFull
796     @@@@@:
797 wakaba 1.1 if (ref $node and
798     UNIVERSAL::isa ($node,
799     <ClassName::ManakaiDOM:ManakaiDOMNodeObject>) and
800 wakaba 1.19 $node->{<H::mn:nodeID>} eq $self->{<H::mn:nodeID>}) {
801 wakaba 1.1 $r = true;
802     }
803 wakaba 1.10 @@@PerlDef:
804     @@@@ForCheck: ForCompact
805     @@@@@:
806     if (ref $node and
807     UNIVERSAL::isa ($node, <ClassName::NodeStem>) and
808 wakaba 1.19 $node->{<H::mn:nodeID>} eq $self->{<H::mn:nodeID>}) {
809 wakaba 1.10 $r = true;
810     }
811 wakaba 1.1 @IntMethod:
812     @@Name: orphanate
813     @@Description:
814     @@@lang:en
815     @@@@:
816     Notifies that this node (and its neibors if any) is no longer
817     part of the main tree. If the new tree containing this node
818     has been referred yet, then the tree is preserved except its
819     tree identifier has changed. Otherwise, i.e. the tree is
820     useless any more, then it is destructed.
821     \
822     {NOTE:: Interaction on deleting a relationship from multiply
823     organized <QUOTE::trees> (such as DOM tree and
824     styled displaying tree) is less studied. This
825     method might be modified or addition of another method(s)
826     might be required when style sheet, XBL, or other
827     technologies has been implemented.
828     \
829     }
830     @@Return:
831     @@@PerlDef:
832 wakaba 1.20 @@@@ForCheck: ForFull
833     @@@@@:
834     if ($self-><M::NodeStem.isExternallyReferred>) {
835     $self-><M::NodeStem.changeTreeID>
836     (<Code::ManakaiDOM:generateUniqueID>);
837     } else {
838     $self-><M::NodeStem.destroy>;
839     }
840     @@@PerlDef:
841     @@@@ForCheck: ForCompact
842     @@@@@:
843     if ($self-><M::NodeStem.isExternallyReferred>) {
844     $self-><M::NodeStem.changeTreeID>
845     (\(<Code::ManakaiDOM:generateUniqueID>));
846     } else {
847     $self-><M::NodeStem.destroy>;
848     }
849 wakaba 1.10 ##NodeStem
850 wakaba 1.1
851     ## -- Public node object
852    
853     ClassDef:
854 wakaba 1.10 @resourceFor: ForFull
855     @resourceFor: ForCompact
856     @resourceFor:
857     ManakaiDOM:ForIF
858    
859     @QName:
860     @@@: NodeRef
861     @@ForCheck:
862     ManakaiDOM:ForIF
863    
864 wakaba 1.1 @QName:
865 wakaba 1.10 @@@:
866     ManakaiDOM:ManakaiDOMNodeReference
867     @@ForCheck: ForFull
868    
869     @Implement:
870     @@@: NodeRef
871     @@ForCheck: ForFull
872    
873     @QName:
874     @@@: ManakaiNodeRef
875     @@ForCheck: ForCompact
876    
877     @Implement:
878     @@@: NodeRef
879     @@ForCheck: ForCompact
880    
881 wakaba 1.1 @Description:
882     @@lang:en
883     @@@:
884     References to the node object corresponding to it. From
885     applications' view, any node object is hidden and
886     <Class::ManakaiDOM:ManakaiDOMNodeReference> seems as if
887     the node itself.
888     @ImplNote:
889     @@lang:en
890     @@@:
891 wakaba 1.13 {P:: A <Class::ManakaiDOM:ManakaiDOMNodeReference> is a blessed hash
892 wakaba 1.1 reference; currently there is a hash key defined:
893     \
894     - <CODE::TreeCore:node>::: A node object
895     (<Class::ManakaiDOM:ManakaiDOMNodeObject>) to which
896     this is referring.
897 wakaba 1.13
898     - <CODE::TreeCore:isWeak>::: Whether the reference is <QUOTE::weak>
899     or not.
900     }
901    
902     @ResourceDef:
903     @@Name: free
904     @@rdf:type: DISLang|Method
905     @@enDesc:
906     Frees the grove referenced by this object. Once
907     this operation is done, results of operations to objects belonging
908     to the grove are unknown.
909     @@ForCheck: ForCompact
910     @@Return:
911     @@@PerlDef:
912 wakaba 1.19 $self->{<H::mn:node>}-><M::NodeStem.destroy>;
913 wakaba 1.1
914     @IntMethod:
915     @@Name: destroy
916     @@Description:
917     @@@lang:en
918     @@@@: Destroy this reference object.
919     @@Operator:
920     @@@ContentType:
921     lang:Perl
922     @@@@: DESTROY
923     @@Return:
924     @@@PerlDef:
925     @@@@@:
926 wakaba 1.19 my $node = $self->{<H::mn:node>};
927 wakaba 1.1 if ($node) {
928 wakaba 1.19 CORE::delete $self->{<H::mn:node>};
929     unless ($self->{<H::mn:isWeak>}) {
930     $node->{<H::mn:rc>}--;
931 wakaba 1.10 unless ($node-><M::NodeStem.isExternallyReferred>) {
932     $node-><M::NodeStem.destroy>;
933 wakaba 1.6 }
934 wakaba 1.1 }
935     } else {
936     warn ref ($self) . q{->DESTROY: there is no associated }.
937     q{node object - you have a global variable or }.
938     qq{potential memory-leak detected\n};
939     }
940     @@@@ImplNote:
941     @@@@@lang:en
942     @@@@@@:
943     {P::Warning during the global destruction might mean:
944     \
945     - there be a loop in the manakai internal implementation -
946     it should be a bug.
947     \
948     - there be a loop created by application, e.g.
949     event handler containing a reference to any node
950     belonging to the same tree.
951     \
952     - there be a global variable that contains a node reference
953     and it is not altered or <Perl::undef>ed until the global
954     destruction.
955     \
956     - or other unknown bad situation.
957     \
958     }
959     @@ImplNote:
960     @@@lang:en
961     @@@@:
962     Don't override this method unintentionally - for example,
963     inheritting <PerlModule::Tie::Array> would hide this method
964     from that class, since that module defines its own
965     destructor.
966 wakaba 1.10 ##NodeRef
967 wakaba 1.6
968     PropDef:
969 wakaba 1.19 @QName: mn|nodeID
970     @enDesc:
971     The globally unique identifier of the node.
972     @mn:stemName: nid
973    
974     PropDef:
975     @QName: mn|treeID
976     @enDesc:
977     The globally unique identifier of the grove to which the
978     node belongs.
979     @mn:stemName: tid
980    
981     PropDef:
982     @QName: mn|rc
983     @enDesc:
984     The number of the reference that points the node.
985     @mn:stemName: rc
986    
987     PropDef:
988     @QName: mn|node
989     @mn:refName: node
990     @rdfs:domain: mn|NodeRef||ManakaiDOM|Perl
991     @rdfs:range: mn|NodeStem||ManakaiDOM|Perl
992    
993     PropDef:
994     @QName: mn|isWeak
995 wakaba 1.6 @enDesc:
996     Whether a reference is weak or not.
997 wakaba 1.19 @rdfs:domain: mn|NodeRef||ManakaiDOM|Perl
998 wakaba 1.16 @Type: DISPerl|Boolean
999 wakaba 1.19 @mn:refName: w
1000    
1001     PropDef:
1002     @QName: mn|stemName
1003     @enDesc:
1004     The key name of the property when it is used in <Class::ManakaiNodeStem
1005     ::ManakaiDOM:Perl>.
1006     @dataType: DISCore|String
1007     @multipleProperties: DISCore|Single
1008     @rdfs:domain: rdfs|Property
1009     @rdfs:subPropertyOf: DISPerl|propHashKey
1010    
1011     PropDef:
1012     @QName: mn|refName
1013     @enDesc:
1014     The key name of the property when it is used in <Class::ManakaiNodeRef
1015     ::ManakaiDOM:Perl>.
1016     @dataType: DISCore|String
1017     @multipleProperties: DISCore|Single
1018     @rdfs:domain: rdfs|Property
1019     @rdfs:subPropertyOf: DISPerl|propHashKey
1020 wakaba 1.6
1021     ElementTypeBinding:
1022     @Name:PropDef
1023     @ElementType:
1024     dis:ResourceDef
1025     @ShadowContent:
1026     @@rdf:type:
1027     rdf:Property
1028 wakaba 1.16 @@For: =ManakaiDOM|all
1029 wakaba 1.6
1030     ElementTypeBinding:
1031     @Name:enDesc
1032     @ElementType:
1033     dis:Description
1034     @ShadowContent:
1035     @@lang:en
1036 wakaba 1.1
1037     ## -- Frequently used code fragments
1038    
1039     ResourceDef:
1040     @QName:
1041     ManakaiDOM:generateUniqueID
1042     @rdf:type:
1043     dis2pm:InlineCode
1044     @Description:
1045     @@lang:en
1046     @@@:
1047     Generates a global-unique opaque string.
1048     \
1049     {NOTE:: A URI reference is generated by this code.
1050     \
1051     }
1052 wakaba 1.16
1053     @For: =ManakaiDOM|Perl
1054    
1055 wakaba 1.1 @PerlDef:
1056     (
1057     sprintf 'mid:%d.%d.%s.dom.manakai@suika.fam.cx#',
1058     time, $$,
1059     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1060     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1061     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1062     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62] .
1063     ['A'..'Z', 'a'..'z', '0'..'9']->[rand 62]
1064     )
1065     ##ManakaiDOM:generateUniqueID
1066    
1067     ## -- lang:dis vocabulary
1068    
1069     TreeElementType:
1070     @QName:
1071     dis:GetProp
1072     @dataType:
1073     dis:TypeQName
1074     @rdfs:range:
1075     rdf:Property
1076     @Description:
1077     @@lang:en
1078     @@@:
1079     Gets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference>
1080     property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property).
1081    
1082     TreeElementType:
1083     @QName:
1084     dis:SetProp
1085     @dataType:
1086     dis:TypeQName
1087     @rdfs:range:
1088     rdf:Property
1089     @Description:
1090     @@lang:en
1091     @@@:
1092     Sets the non-nodal value of a <Class::ManakaiDOM:ManakaiDOMNodeReference>
1093     property (actualy <Class::ManakaiDOM:ManakaiDOMNodeObject> property).
1094    
1095     ## -- Syntax sugar
1096    
1097     ElementTypeBinding:
1098     @Name: TreeElementType
1099     @ElementType:
1100     dis:ResourceDef
1101     @ShadowContent:
1102     @@rdf:type:
1103     DISLang:TreeElementType
1104 wakaba 1.16 @@For: =ManakaiDOM|all
1105 wakaba 1.1
1106     ElementTypeBinding:
1107     @Name: ClassDef
1108     @ElementType:
1109     dis:ResourceDef
1110     @ShadowContent:
1111     @@rdf:type:
1112     @@@@:
1113 wakaba 1.10 dis:MultipleResource
1114     @@@ForCheck:
1115     !ForFull !ForCompact !ManakaiDOM:ForIF
1116     @@rdf:type:
1117     @@@@:
1118     ManakaiDOM:IF
1119     @@@ForCheck:
1120     ManakaiDOM:ForIF
1121     @@rdf:type:
1122     @@@@:
1123     ManakaiDOM:Class
1124     @@@ForCheck: ForFull
1125     @@rdf:type:
1126     @@@@:
1127     ManakaiDOM:Class
1128     @@@ForCheck: ForCompact
1129 wakaba 1.2 @@ForCheck:
1130     ManakaiDOM:Perl
1131 wakaba 1.10
1132     ForDef:
1133     @QName:
1134     mn:ForFull
1135     @ISA:
1136     ManakaiDOM:ForClass
1137    
1138     ForDef:
1139     @QName:
1140     mn:ForCompact
1141     @ISA:
1142     ManakaiDOM:ForClass
1143 wakaba 1.1
1144     ElementTypeBinding:
1145     @Name: IntMethod
1146     @ElementType:
1147     dis:ResourceDef
1148     @ShadowContent:
1149     @@rdf:type:
1150     DISLang:Method
1151     @@ManakaiDOM:isForInternal:1
1152    
1153     ElementTypeBinding:
1154     @Name: Return
1155     @ElementType:
1156     dis:ResourceDef
1157     @ShadowContent:
1158     @@rdf:type:
1159     DISLang:MethodReturn
1160    
1161     ElementTypeBinding:
1162     @Name: Param
1163     @ElementType:
1164     dis:ResourceDef
1165     @ShadowContent:
1166     @@rdf:type:
1167     DISLang:MethodParameter
1168    
1169     ElementTypeBinding:
1170     @Name: PerlDef
1171     @ElementType:
1172     dis:Def
1173     @ShadowContent:
1174     @@ContentType:
1175     lang:Perl
1176    
1177     ElementTypeBinding:
1178     @Name: InCase
1179     @ElementType:
1180     dis:ResourceDef
1181     @ShadowContent:
1182     @@rdf:type:
1183     ManakaiDOM:InCase

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24