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

Last change on this file since 760 was 750, checked in by イグトランス (egtra), 16 years ago

BOOST_FOREACHを可能なものはVC++ 2005 for eachへ置換(やや速くなる)。

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