[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 | {
|
---|
[810] | 9 | typedef std::vector<std::string> Base;
|
---|
[215] | 10 | // XMLシリアライズ用
|
---|
| 11 | private:
|
---|
| 12 | friend class boost::serialization::access;
|
---|
| 13 | template<class Archive> void serialize(Archive& ar, const unsigned int version)
|
---|
| 14 | {
|
---|
[523] | 15 | ar & boost::serialization::make_nvp("vector_string", boost::serialization::base_object<std::vector<std::string>>(*this));
|
---|
[215] | 16 | }
|
---|
| 17 |
|
---|
| 18 |
|
---|
| 19 | public:
|
---|
[810] | 20 | NamespaceScopes() {}
|
---|
| 21 | NamespaceScopes(NamespaceScopes const& y)
|
---|
| 22 | : Base(y)
|
---|
| 23 | {
|
---|
| 24 | }
|
---|
| 25 | NamespaceScopes(NamespaceScopes&& y)
|
---|
| 26 | : Base(std::move(y))
|
---|
| 27 | {
|
---|
| 28 | }
|
---|
[505] | 29 | NamespaceScopes( const std::string &namespaceStr );
|
---|
[737] | 30 | NamespaceScopes( NamespaceScopes::const_iterator first, NamespaceScopes::const_iterator last )
|
---|
[810] | 31 | : Base(first, last)
|
---|
[737] | 32 | {
|
---|
| 33 | }
|
---|
[215] | 34 | ~NamespaceScopes(){}
|
---|
| 35 |
|
---|
[737] | 36 | void append( const NamespaceScopes &namespaceScopes )
|
---|
| 37 | {
|
---|
| 38 | insert( end(), namespaceScopes.begin(), namespaceScopes.end() );
|
---|
| 39 | }
|
---|
| 40 |
|
---|
[810] | 41 | NamespaceScopes& operator +=(const NamespaceScopes &namespaceScopes)
|
---|
| 42 | {
|
---|
| 43 | append(namespaceScopes);
|
---|
| 44 | return *this;
|
---|
| 45 | }
|
---|
| 46 |
|
---|
[505] | 47 | std::string ToString() const
|
---|
[215] | 48 | {
|
---|
[505] | 49 | std::string namespaceStr;
|
---|
| 50 | const std::vector<std::string> &me = *this;
|
---|
[215] | 51 |
|
---|
| 52 | bool isFirst = true;
|
---|
[750] | 53 | foreach( const std::string &itemStr, me ){
|
---|
[215] | 54 | if( isFirst ){
|
---|
| 55 | isFirst = false;
|
---|
| 56 | }
|
---|
| 57 | else{
|
---|
[737] | 58 | namespaceStr += '.';
|
---|
[215] | 59 | }
|
---|
| 60 |
|
---|
| 61 | namespaceStr += itemStr;
|
---|
| 62 | }
|
---|
| 63 | return namespaceStr;
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | // 等しいかをチェック
|
---|
[505] | 67 | bool IsEqual( const std::string &name ) const
|
---|
[215] | 68 | {
|
---|
| 69 | if( ToString() == name ){
|
---|
| 70 | return true;
|
---|
| 71 | }
|
---|
| 72 | return false;
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | // 等しいかをチェック
|
---|
[669] | 76 | bool IsEqual( const NamespaceScopes &namespaceScopes ) const;
|
---|
[215] | 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 | }
|
---|
[737] | 88 | return std::equal( baseNamespaceScopes.begin(), baseNamespaceScopes.end(), entryNamespaceScopes.begin() );
|
---|
[215] | 89 | }
|
---|
| 90 | };
|
---|
| 91 |
|
---|
[810] | 92 | NamespaceScopes operator +(const NamespaceScopes &lhs, const NamespaceScopes &rhs);
|
---|
| 93 |
|
---|
[737] | 94 | inline bool operator ==( const NamespaceScopes &lhs, const NamespaceScopes &rhs )
|
---|
| 95 | {
|
---|
| 96 | return lhs.IsEqual( rhs );
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[505] | 99 | class NamespaceScopesCollection : public std::vector<NamespaceScopes>
|
---|
[215] | 100 | {
|
---|
[810] | 101 | typedef std::vector<NamespaceScopes> Base;
|
---|
[215] | 102 | // XMLシリアライズ用
|
---|
| 103 | private:
|
---|
| 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 |
|
---|
| 110 | public:
|
---|
[810] | 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 | }
|
---|
[215] | 123 | bool IsExist( const NamespaceScopes &namespaceScopes ) const
|
---|
| 124 | {
|
---|
[737] | 125 | return std::find( this->begin(), this->end(), namespaceScopes ) != this->end();
|
---|
[215] | 126 | }
|
---|
[505] | 127 | bool IsExist( const std::string &namespaceStr ) const
|
---|
[215] | 128 | {
|
---|
| 129 | return IsExist( NamespaceScopes( namespaceStr ) );
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | bool IsImported( const NamespaceScopes &namespaceScopes ) const
|
---|
| 133 | {
|
---|
[737] | 134 | return IsExist( namespaceScopes );
|
---|
[215] | 135 | }
|
---|
| 136 |
|
---|
| 137 | void SplitNamespace( const char *fullName, char *namespaceStr, char *simpleName ) const;
|
---|
| 138 | };
|
---|
[505] | 139 |
|
---|
| 140 |
|
---|
| 141 | }}}
|
---|