source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/NamespaceSupporter.h@ 668

Last change on this file since 668 was 668, checked in by dai_9181, 16 years ago

NamespaceSupporter::ClearImportedNamespacesを追加。
NamespaceSupporter::GetImportedNamespacesをconstにした。

File size: 3.1 KB
RevLine 
[195]1#pragma once
2
[507]3namespace ActiveBasic{ namespace Common{ namespace Lexical{
4
5
[195]6class NamespaceSupporter
7{
[507]8 const NamespaceScopesCollection *allNamespaceScopesCollection;
9
[195]10 // Importsされた名前空間
11 NamespaceScopesCollection importedNamespaces;
12
13 // 現在の名前空間
14 NamespaceScopes livingNamespaceScopes;
15
16public:
[507]17 NamespaceSupporter()
18 : allNamespaceScopesCollection( NULL )
19 {
20 }
21
22 void RegistAllNamespaceScopesCollection( const NamespaceScopesCollection *allNamespaceScopesCollection )
23 {
24 this->allNamespaceScopesCollection = allNamespaceScopesCollection;
25 }
26
[668]27 const NamespaceScopesCollection &GetImportedNamespaces()
[195]28 {
29 return importedNamespaces;
30 }
31 void SetImportedNamespaces( const NamespaceScopesCollection &namespaces )
32 {
33 this->importedNamespaces = namespaces;
34 }
[668]35 void ClearImportedNamespaces()
36 {
37 this->importedNamespaces.clear();
38 }
[507]39 bool ImportsNamespace( const NamespaceScopes &namespaceScopes );
[199]40 bool ImportsNamespace( const std::string &namespaceStr );
[195]41
42 NamespaceScopes &GetLivingNamespaceScopes()
43 {
44 return livingNamespaceScopes;
45 }
[198]46 void SetLivingNamespaceScopes( const NamespaceScopes &namespaceScopes )
47 {
48 this->livingNamespaceScopes = namespaceScopes;
49 }
[195]50 bool IsLiving( const NamespaceScopes &namespaceScopes ) const
51 {
52 return NamespaceScopes::IsBelong( namespaceScopes, livingNamespaceScopes );
53 }
54
55
56 // 包括しているかをチェック
57 // 例:
58 // this = "Discoversoft.ActiveBasic"
59 // living = "Discoversoft.ActiveBasic"
60 // entryName = "ActiveBasic"
61 // この場合、living は entryName を包括している。
[507]62 bool IsCoverd( const NamespaceScopes &namespaceScopes, const std::string &entryName ) const
[195]63 {
[507]64 if( namespaceScopes.IsEqual( entryName ) )
65 {
[195]66 return true;
67 }
68
[507]69 std::string thisStr = namespaceScopes.ToString();
[195]70
71 NamespaceScopes tempLivingNamespaceScopes = livingNamespaceScopes;
72
[507]73 while( tempLivingNamespaceScopes.size() )
74 {
75 std::string tempStr = tempLivingNamespaceScopes.ToString() + "." + entryName;
76 if( thisStr == tempStr )
77 {
[195]78 return true;
79 }
80
81 tempLivingNamespaceScopes.pop_back();
82 }
83 return false;
84 }
85 bool IsCoverd( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const
86 {
87 return IsCoverd( baseNamespaceScopes, entryNamespaceScopes.ToString() );
88 }
89
90
91 // 指定された名前空間が同一エリアと見なされるかどうかをチェック
[504]92 bool IsSameAreaNamespace( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const
93 {
94 if( entryNamespaceScopes.size() )
95 {
96 if( IsCoverd( baseNamespaceScopes, entryNamespaceScopes ) )
97 {
[195]98 // 包括しているときは同一と見なす
99 return true;
100 }
101 }
102 else{
[504]103 if( baseNamespaceScopes.size() )
104 {
[195]105 // 名前空間の判断が必要なとき
106 if( this->importedNamespaces.IsImported( baseNamespaceScopes )
[504]107 || IsLiving( baseNamespaceScopes ) )
108 {
[195]109 // Using指定があるとき
110 // または
111 // 指定された名前空間が現在の名前空間スコープと同一のとき
112 return true;
113 }
114 }
115 else{
116 return true;
117 }
118 }
119
120 return false;
121 }
122};
[507]123
124
125}}}
Note: See TracBrowser for help on using the repository browser.