[215] | 1 | #pragma once
|
---|
[737] | 2 | #include <algorithm>
|
---|
[215] | 3 |
|
---|
[505] | 4 | namespace ActiveBasic{ namespace Common{ namespace Lexical{
|
---|
[215] | 5 |
|
---|
[505] | 6 |
|
---|
| 7 | class NamespaceScopes : public std::vector<std::string>
|
---|
[215] | 8 | {
|
---|
| 9 | // XMLシリアライズ用
|
---|
| 10 | private:
|
---|
| 11 | friend class boost::serialization::access;
|
---|
| 12 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 13 | {
|
---|
[523] | 14 | ar & boost::serialization::make_nvp("vector_string", boost::serialization::base_object<std::vector<std::string>>(*this));
|
---|
[215] | 15 | }
|
---|
| 16 |
|
---|
| 17 |
|
---|
| 18 | public:
|
---|
| 19 | NamespaceScopes(){}
|
---|
[505] | 20 | NamespaceScopes( const std::string &namespaceStr );
|
---|
[737] | 21 | NamespaceScopes( NamespaceScopes::const_iterator first, NamespaceScopes::const_iterator last )
|
---|
| 22 | : std::vector<std::string>( first, last )
|
---|
| 23 | {
|
---|
| 24 | }
|
---|
[215] | 25 | ~NamespaceScopes(){}
|
---|
| 26 |
|
---|
[669] | 27 | NamespaceScopes operator+ ( const NamespaceScopes &namespaceScopes ) const;
|
---|
| 28 |
|
---|
[737] | 29 | void append( const NamespaceScopes &namespaceScopes )
|
---|
| 30 | {
|
---|
| 31 | insert( end(), namespaceScopes.begin(), namespaceScopes.end() );
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[505] | 34 | std::string ToString() const
|
---|
[215] | 35 | {
|
---|
[505] | 36 | std::string namespaceStr;
|
---|
| 37 | const std::vector<std::string> &me = *this;
|
---|
[215] | 38 |
|
---|
| 39 | bool isFirst = true;
|
---|
[750] | 40 | foreach( const std::string &itemStr, me ){
|
---|
[215] | 41 | if( isFirst ){
|
---|
| 42 | isFirst = false;
|
---|
| 43 | }
|
---|
| 44 | else{
|
---|
[737] | 45 | namespaceStr += '.';
|
---|
[215] | 46 | }
|
---|
| 47 |
|
---|
| 48 | namespaceStr += itemStr;
|
---|
| 49 | }
|
---|
| 50 | return namespaceStr;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | // 等しいかをチェック
|
---|
[505] | 54 | bool IsEqual( const std::string &name ) const
|
---|
[215] | 55 | {
|
---|
| 56 | if( ToString() == name ){
|
---|
| 57 | return true;
|
---|
| 58 | }
|
---|
| 59 | return false;
|
---|
| 60 | }
|
---|
| 61 |
|
---|
| 62 | // 等しいかをチェック
|
---|
[669] | 63 | bool IsEqual( const NamespaceScopes &namespaceScopes ) const;
|
---|
[215] | 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 | }
|
---|
[737] | 75 | return std::equal( baseNamespaceScopes.begin(), baseNamespaceScopes.end(), entryNamespaceScopes.begin() );
|
---|
[215] | 76 | }
|
---|
| 77 | };
|
---|
| 78 |
|
---|
[737] | 79 | inline bool operator ==( const NamespaceScopes &lhs, const NamespaceScopes &rhs )
|
---|
| 80 | {
|
---|
| 81 | return lhs.IsEqual( rhs );
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[505] | 84 | class NamespaceScopesCollection : public std::vector<NamespaceScopes>
|
---|
[215] | 85 | {
|
---|
| 86 | // XMLシリアライズ用
|
---|
| 87 | private:
|
---|
| 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 |
|
---|
| 94 | public:
|
---|
| 95 | bool IsExist( const NamespaceScopes &namespaceScopes ) const
|
---|
| 96 | {
|
---|
[737] | 97 | return std::find( this->begin(), this->end(), namespaceScopes ) != this->end();
|
---|
[215] | 98 | }
|
---|
[505] | 99 | bool IsExist( const std::string &namespaceStr ) const
|
---|
[215] | 100 | {
|
---|
| 101 | return IsExist( NamespaceScopes( namespaceStr ) );
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | bool IsImported( const NamespaceScopes &namespaceScopes ) const
|
---|
| 105 | {
|
---|
[737] | 106 | return IsExist( namespaceScopes );
|
---|
[215] | 107 | }
|
---|
| 108 |
|
---|
| 109 | void SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const;
|
---|
| 110 | };
|
---|
[505] | 111 |
|
---|
| 112 |
|
---|
| 113 | }}}
|
---|