forked from YAYA-shiori/yaya-shiori
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobalvariable.cpp
101 lines (89 loc) · 2.96 KB
/
globalvariable.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//
// AYA version 5
//
// グローバル変数を扱うクラス CGlobalVariable
// written by umeici. 2004
//
#if defined(WIN32) || defined(_WIN32_WCE)
# include "stdafx.h"
#endif
#include <vector>
#include "variable.h"
#include "ayavm.h"
#include "basis.h"
#include "globaldef.h"
//////////DEBUG/////////////////////////
#ifdef _WINDOWS
#ifdef _DEBUG
#include <crtdbg.h>
#define new new( _NORMAL_BLOCK, __FILE__, __LINE__)
#endif
#endif
////////////////////////////////////////
/* -----------------------------------------------------------------------
* 関数名 : CGlobalVariable::Make
* 機能概要: 変数を作成します
* 引数 : erased 0/1=有効状態/消去状態
*
* 返値 : 追加した位置
*
* 指定された名前の変数が既に存在していた場合は追加は行わず、既存の位置を返します
* -----------------------------------------------------------------------
*/
int CGlobalVariable::Make(const aya::string_t &name, bool erased) {
// 既に存在するか調べ、存在していたらそれを返す
aya::indexmap::const_iterator it = varmap.find(name);
if( it != varmap.end() ) {
int idx = it->second;
if(!vm.basis().IsRun()) {
if(erased)
var[idx].Erase();
else
var[idx].Enable();
}
return idx;
}
// 作成
CVariable addvariable(name);
if(erased)
addvariable.Erase();
else
addvariable.Enable();
var.emplace_back(addvariable);
int idx = var.size() - 1;
varmap.insert(aya::indexmap::value_type(name,idx));
return idx;
}
/* -----------------------------------------------------------------------
* 関数名 : CGlobalVariable::GetMacthedLongestNameLength
* 機能概要: 指定された文字列にマッチする名前を持つ変数を探し、マッチした長さを返します
*
* 複数見つかった場合は最長のものを返します。見つからなかった場合は0を返します
* -----------------------------------------------------------------------
*/
size_t CGlobalVariable::GetMacthedLongestNameLength(const aya::string_t &name)
{
size_t max_len = 0;
for(std::vector<CVariable>::iterator it = var.begin(); it != var.end(); it++) {
size_t len = it->name.size();
if(!it->IsErased() && max_len < len && !name.compare(0,len,it->name,0,len))
max_len = len;
}
return max_len;
}
/* -----------------------------------------------------------------------
* 関数名 : CGlobalVariable::GetIndex
* 機能概要: 指定された名前の変数の位置を返します
*
* 見つからなかった場合は-1を返します
* -----------------------------------------------------------------------
*/
int CGlobalVariable::GetIndex(const aya::string_t &name)
{
aya::indexmap::const_iterator it = varmap.find(name);
if( it != varmap.end() ) {
int idx = it->second;
return var[idx].IsErased() ? -1 : idx;
}
return -1;
}