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

Last change on this file since 593 was 523, checked in by dai_9181, 17 years ago

ヘッダファイルを整理中

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