/[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.12 - (hide annotations) (download)
Tue Aug 30 12:30:45 2005 UTC (19 years, 10 months ago) by wakaba
Branch: MAIN
Changes since 1.11: +9 -9 lines
New things to support generation of the document added

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24