1 | #pragma once |
---|
2 | |
---|
3 | class NamespaceSupporter |
---|
4 | { |
---|
5 | // Importsされた名前空間 |
---|
6 | NamespaceScopesCollection importedNamespaces; |
---|
7 | |
---|
8 | // 現在の名前空間 |
---|
9 | NamespaceScopes livingNamespaceScopes; |
---|
10 | |
---|
11 | public: |
---|
12 | NamespaceScopesCollection &GetImportedNamespaces() |
---|
13 | { |
---|
14 | return importedNamespaces; |
---|
15 | } |
---|
16 | void SetImportedNamespaces( const NamespaceScopesCollection &namespaces ) |
---|
17 | { |
---|
18 | this->importedNamespaces = namespaces; |
---|
19 | } |
---|
20 | bool ImportsNamespace( const std::string &namespaceStr ); |
---|
21 | |
---|
22 | NamespaceScopes &GetLivingNamespaceScopes() |
---|
23 | { |
---|
24 | return livingNamespaceScopes; |
---|
25 | } |
---|
26 | void SetLivingNamespaceScopes( const NamespaceScopes &namespaceScopes ) |
---|
27 | { |
---|
28 | this->livingNamespaceScopes = namespaceScopes; |
---|
29 | } |
---|
30 | bool IsLiving( const NamespaceScopes &namespaceScopes ) const |
---|
31 | { |
---|
32 | return NamespaceScopes::IsBelong( namespaceScopes, livingNamespaceScopes ); |
---|
33 | } |
---|
34 | |
---|
35 | |
---|
36 | // 包括しているかをチェック |
---|
37 | // 例: |
---|
38 | // this = "Discoversoft.ActiveBasic" |
---|
39 | // living = "Discoversoft.ActiveBasic" |
---|
40 | // entryName = "ActiveBasic" |
---|
41 | // この場合、living は entryName を包括している。 |
---|
42 | bool IsCoverd( const NamespaceScopes &namespaceScopes, const string &entryName ) const |
---|
43 | { |
---|
44 | if( namespaceScopes.IsEqual( entryName ) ){ |
---|
45 | return true; |
---|
46 | } |
---|
47 | |
---|
48 | string thisStr = namespaceScopes.ToString(); |
---|
49 | |
---|
50 | NamespaceScopes tempLivingNamespaceScopes = livingNamespaceScopes; |
---|
51 | |
---|
52 | while( tempLivingNamespaceScopes.size() ){ |
---|
53 | string tempStr = tempLivingNamespaceScopes.ToString() + "." + entryName; |
---|
54 | if( thisStr == tempStr ){ |
---|
55 | return true; |
---|
56 | } |
---|
57 | |
---|
58 | tempLivingNamespaceScopes.pop_back(); |
---|
59 | } |
---|
60 | return false; |
---|
61 | } |
---|
62 | bool IsCoverd( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const |
---|
63 | { |
---|
64 | return IsCoverd( baseNamespaceScopes, entryNamespaceScopes.ToString() ); |
---|
65 | } |
---|
66 | |
---|
67 | |
---|
68 | // 指定された名前空間が同一エリアと見なされるかどうかをチェック |
---|
69 | bool IsSameAreaNamespace( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes ) const |
---|
70 | { |
---|
71 | if( entryNamespaceScopes.size() ) |
---|
72 | { |
---|
73 | if( IsCoverd( baseNamespaceScopes, entryNamespaceScopes ) ) |
---|
74 | { |
---|
75 | // 包括しているときは同一と見なす |
---|
76 | return true; |
---|
77 | } |
---|
78 | } |
---|
79 | else{ |
---|
80 | if( baseNamespaceScopes.size() ) |
---|
81 | { |
---|
82 | // 名前空間の判断が必要なとき |
---|
83 | if( this->importedNamespaces.IsImported( baseNamespaceScopes ) |
---|
84 | || IsLiving( baseNamespaceScopes ) ) |
---|
85 | { |
---|
86 | // Using指定があるとき |
---|
87 | // または |
---|
88 | // 指定された名前空間が現在の名前空間スコープと同一のとき |
---|
89 | return true; |
---|
90 | } |
---|
91 | } |
---|
92 | else{ |
---|
93 | return true; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | return false; |
---|
98 | } |
---|
99 | |
---|
100 | static bool CollectNamespaces( const char *source, NamespaceScopesCollection &namespaceScopesCollection ); |
---|
101 | }; |
---|