OSDN Git Service

beca799d0fa0106d781dda0a30ac7f059ecd63fd
[chnosproject/AI004.git] / aimtbase.js
1 function AI_MemoryTag(typeUUIDStr){
2         //保存対象
3         this.uuid = null;
4         this.type = typeUUIDStr;
5         this.createdDate = new Date();
6         
7         //内部データ(保存されない)
8         //this.isBootstrap = false;     //上書き警告抑制用
9         
10         //初期化
11         this.initUUID();
12 }
13 AI_MemoryTag.prototype = {
14         Type_CandidateWord: "2fba8fc1-2b9a-46e0-8ade-455c0bd30637",
15         Type_Word: "d5eef85c-a796-4d04-bb72-8d45c94c5e4f",
16         
17         //http://codedehitokoto.blogspot.jp/2012/01/javascriptuuid.html
18         initUUID: function(){
19                 if(!this.uuid){
20                         var f = this.initUUIDSub;
21                         this.uuid = f() + f() + "-" + 
22                                                 f() + "-" + 
23                                                 f() + "-" + 
24                                                 f() + "-" + 
25                                                 f() + f() + f();
26                 }
27         },
28         initUUIDSub: function(){
29                 return (((1 + Math.random()) * 0x10000) | 0).toString(16).toLowerCase().substring(1);
30         },
31         parseToStringData: function(data){
32                 //uuid:type:
33                 var d = new Object();
34                 //
35                 d.id = this.uuid;
36                 d.type = this.type;
37                 d.cDate = this.createdDate.toUTCString();
38                 //
39                 d.data = data;
40                 //
41                 return this.parseArrayToStringSource(d);
42         },
43         loadFromMemoryData: function(data){
44                 this.uuid = data.id;
45                 this.type = data.type;
46                 this.createdDate = new Date(data.cDate);
47                 if(data.data){
48                         if(this.loadFromMemoryData != AI_MemoryTag.prototype.loadFromMemoryData){
49                                 this.loadFromMemoryData(data.data);
50                         }
51                 }
52         },
53         parseArrayToStringSource: function(anArray){
54                 if(!anArray){
55                         return "null";
56                 }
57                 var srcstr = "var t=";
58                 srcstr += this.parseArrayToStringSourceSub(anArray);
59                 srcstr += ";t;";
60                 return srcstr;
61         },
62         parseArrayToStringSourceSub: function(anArray){
63                 if(!anArray){
64                         return "null";
65                 }
66                 var srcstr = "{";
67                 for(var k in anArray){
68                         var v = anArray[k];
69                         var t = Object.prototype.toString.call(v);
70                         if(v instanceof Array){
71                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
72                         } else if(!isNaN(v) && v.toString().replace(/\s+/g, "").length > 0){
73                                 //isNaNだけでは数値判定できないので、文字列化後の空白文字を削除した長さも検査している。
74                                 srcstr += k + ":" + v + ",";
75                         } else if(t == "[object String]"){
76                                 //文字列として変換
77                                 srcstr += k + ":'" + v + "',";
78                         } else if(t == "[object Object]"){
79                                 srcstr += k + ":" + this.parseArrayToStringSourceSub(v) + ",";
80                         } else{
81                                 srcstr += k + ":undefined,";
82                         }
83                 }
84                 if(srcstr.charAt(srcstr.length - 1) == ","){
85                         //最後の余計なカンマを削除
86                         srcstr = srcstr.slice(0, srcstr.length - 1);
87                 }
88                 srcstr += "}";
89                 return srcstr;
90         },
91 }