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

Last change on this file was 829, checked in by イグトランス (egtra), 13 years ago

svn:eol-styleとsvn:mime-type(文字コード指定含む)の設定

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/plain; charset=Shift_JIS
File size: 3.6 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 typedef std::vector<std::string> Base;
10 // XMLシリアライズ用
11private:
12 friend class boost::serialization::access;
13 template<class Archive> void serialize(Archive& ar, const unsigned int version)
14 {
15 ar & boost::serialization::make_nvp("vector_string", boost::serialization::base_object<std::vector<std::string>>(*this));
16 }
17
18
19public:
20 NamespaceScopes() {}
21 NamespaceScopes(NamespaceScopes const& y)
22 : Base(y)
23 {
24 }
25 NamespaceScopes(NamespaceScopes&& y)
26 : Base(std::move(y))
27 {
28 }
29 NamespaceScopes( const std::string &namespaceStr );
30 NamespaceScopes( NamespaceScopes::const_iterator first, NamespaceScopes::const_iterator last )
31 : Base(first, last)
32 {
33 }
34 ~NamespaceScopes(){}
35
36 void append( const NamespaceScopes &namespaceScopes )
37 {
38 insert( end(), namespaceScopes.begin(), namespaceScopes.end() );
39 }
40
41 NamespaceScopes& operator +=(const NamespaceScopes &namespaceScopes)
42 {
43 append(namespaceScopes);
44 return *this;
45 }
46
47 std::string ToString() const
48 {
49 std::string namespaceStr;
50 const std::vector<std::string> &me = *this;
51
52 bool isFirst = true;
53 foreach( const std::string &itemStr, me ){
54 if( isFirst ){
55 isFirst = false;
56 }
57 else{
58 namespaceStr += '.';
59 }
60
61 namespaceStr += itemStr;
62 }
63 return namespaceStr;
64 }
65
66 // 等しいかをチェック
67 bool IsEqual( const std::string &name ) const
68 {
69 if( ToString() == name ){
70 return true;
71 }
72 return false;
73 }
74
75 // 等しいかをチェック
76 bool IsEqual( const NamespaceScopes &namespaceScopes ) const;
77
78 // 所属しているかをチェック
79 // 例:
80 // baseNamespaceScopes = "Discoversoft"
81 // entryNamespaceScopes = "Discoversoft.ActiveBasic"
82 // この場合、entryNamespaceScopes は baseNamespaceScopes に所属している。
83 static bool IsBelong( const NamespaceScopes &baseNamespaceScopes, const NamespaceScopes &entryNamespaceScopes )
84 {
85 if( baseNamespaceScopes.size() > entryNamespaceScopes.size() ){
86 return false;
87 }
88 return std::equal( baseNamespaceScopes.begin(), baseNamespaceScopes.end(), entryNamespaceScopes.begin() );
89 }
90};
91
92NamespaceScopes operator +(const NamespaceScopes &lhs, const NamespaceScopes &rhs);
93
94inline bool operator ==( const NamespaceScopes &lhs, const NamespaceScopes &rhs )
95{
96 return lhs.IsEqual( rhs );
97}
98
99class NamespaceScopesCollection : public std::vector<NamespaceScopes>
100{
101 typedef std::vector<NamespaceScopes> Base;
102 // XMLシリアライズ用
103private:
104 friend class boost::serialization::access;
105 template<class Archive> void serialize(Archive& ar, const unsigned int version)
106 {
107 ar & boost::serialization::make_nvp("vector_NamespaceScopes", boost::serialization::base_object<vector<NamespaceScopes>>(*this));
108 }
109
110public:
111 NamespaceScopesCollection() : Base() {}
112 NamespaceScopesCollection(NamespaceScopesCollection&& y) : Base(std::move(y)) {}
113 NamespaceScopesCollection(NamespaceScopesCollection const& y) : Base(y) {}
114 NamespaceScopesCollection& operator =(NamespaceScopesCollection&& y)
115 {
116 Base::operator =(std::move(y));
117 return *this;
118 }
119 NamespaceScopesCollection& operator =(NamespaceScopesCollection const& y)
120 {
121 return operator =(NamespaceScopesCollection(y));
122 }
123 bool IsExist( const NamespaceScopes &namespaceScopes ) const
124 {
125 return std::find( this->begin(), this->end(), namespaceScopes ) != this->end();
126 }
127 bool IsExist( const std::string &namespaceStr ) const
128 {
129 return IsExist( NamespaceScopes( namespaceStr ) );
130 }
131
132 bool IsImported( const NamespaceScopes &namespaceScopes ) const
133 {
134 return IsExist( namespaceScopes );
135 }
136
137 void SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const;
138};
139
140
141}}}
Note: See TracBrowser for help on using the repository browser.