source: dev/trunk/ab5.0/abdev/ab_common/include/Lexical/Namespace.h@ 719

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

NamespaceScopes::IsEqualを高速化した(他、リファクタリング)。

File size: 3.0 KB
Line 
1#pragma once
2
3
4namespace ActiveBasic{ namespace Common{ namespace Lexical{
5
6
7class NamespaceScopes : public std::vector<std::string>
8{
9 // XMLシリアライズ用
10private:
11 friend class boost::serialization::access;
12 template<class Archive> void serialize(Archive& ar, const unsigned int version)
13 {
14 ar & boost::serialization::make_nvp("vector_string", boost::serialization::base_object<std::vector<std::string>>(*this));
15 }
16
17
18public:
19 NamespaceScopes(){}
20 NamespaceScopes( const std::string &namespaceStr );
21 ~NamespaceScopes(){}
22
23 NamespaceScopes operator+ ( const NamespaceScopes &namespaceScopes ) const;
24
25 std::string ToString() const
26 {
27 std::string namespaceStr;
28 const std::vector<std::string> &me = *this;
29
30 bool isFirst = true;
31 BOOST_FOREACH( const std::string &itemStr, me ){
32 if( isFirst ){
33 isFirst = false;
34 }
35 else{
36 namespaceStr += ".";
37 }
38
39 namespaceStr += itemStr;
40 }
41 return namespaceStr;
42 }
43
44 // 等しいかをチェック
45 bool IsEqual( const std::string &name ) const
46 {
47 if( ToString() == name ){
48 return true;
49 }
50 return false;
51 }
52
53 // 等しいかをチェック
54 bool IsEqual( const NamespaceScopes &namespaceScopes ) const;
55
56 // 所属しているかをチェック
57 // 例:
58 // baseNamespaceScopes = "Discoversoft"
59 // entryNamespaceScopes = "Discoversoft.ActiveBasic"
60 // この場合、entryNamespaceScopes は baseNamespaceScopes に所属している。
61 static bool IsBelong( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes )
62 {
63 if( baseNamespaceScopes.size() > entryNamespaceScopes.size() ){
64 return false;
65 }
66
67 for( int i=0; i<(int)baseNamespaceScopes.size(); i++ ){
68 if( baseNamespaceScopes[i] != entryNamespaceScopes[i] ){
69 return false;
70 }
71 }
72 return true;
73 }
74};
75
76class NamespaceScopesCollection : public std::vector<NamespaceScopes>
77{
78 // XMLシリアライズ用
79private:
80 friend class boost::serialization::access;
81 template<class Archive> void serialize(Archive& ar, const unsigned int version)
82 {
83 ar & boost::serialization::make_nvp("vector_NamespaceScopes", boost::serialization::base_object<vector<NamespaceScopes>>(*this));
84 }
85
86public:
87 bool IsExist( const NamespaceScopes &namespaceScopes ) const
88 {
89 const NamespaceScopesCollection &namespaceScopesCollection = *this;
90 BOOST_FOREACH( const NamespaceScopes &tempNamespaceScopes, namespaceScopesCollection ){
91 if( tempNamespaceScopes.IsEqual( namespaceScopes ) ){
92 return true;
93 }
94 }
95 return false;
96 }
97 bool IsExist( const std::string &namespaceStr ) const
98 {
99 return IsExist( NamespaceScopes( namespaceStr ) );
100 }
101
102 bool IsImported( const NamespaceScopes &namespaceScopes ) const
103 {
104 const NamespaceScopesCollection &namespaceScopesCollection = *this;
105 BOOST_FOREACH( const NamespaceScopes &tempNamespaceScopes, namespaceScopesCollection )
106 {
107 if( namespaceScopes.IsEqual( tempNamespaceScopes ) )
108 {
109 return true;
110 }
111 }
112 return false;
113 }
114
115 void SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const;
116};
117
118
119}}}
Note: See TracBrowser for help on using the repository browser.