source: dev/trunk/abdev/BasicCompiler_Common/include/Namespace.h@ 215

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

BoostSerializationSupportのクラステンプレートインスタンスを明示的に生成するようにした(コンパイル時間の短縮)

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