root/trunk/scintillamacros.h

Revision 5, 1.8 kB (checked in by qbert, 6 years ago)

Initial ( and last :( ) commit

Line 
1 #ifndef ElephantMACRO_H
2 #define ElephantMACRO_H
3
4
5 struct MacroMsg {
6 public:
7     MacroMsg ( long Msg, WPARAM w, LPARAM l ) : msg(Msg),wparam(w), lparam(l) { }
8     MacroMsg ( long Msg, const string& t ) : msg(Msg) ,text(t) {}
9    
10     long msg;
11     WPARAM wparam;
12     LPARAM lparam;
13     string text;
14 };
15
16 class ElephantMacro {
17 public:
18     vector<MacroMsg> msgs;
19
20     void Record (long msg, WPARAM wparam, LPARAM lparam ) {     
21         msgs.push_back(MacroMsg(msg,wparam,lparam ));
22     }
23
24     void Record (long msg, char* t ) {
25         msgs.push_back(MacroMsg(msg,t ));
26     }
27
28 };
29
30 inline bool SaveMacro(const string& path, ElephantMacro* m ) {
31
32     // this prolly needs changing, i just use this cause of the available functions
33     // already written for Elephant
34
35     int size = m->msgs.size();
36     ofstream out(path.c_str() );
37
38     if ( out.good() ) {
39
40         for ( int i = 0;i < size;i++) {
41
42             m->msgs[i].msg == -1
43                 ?
44                 out << -1 << "\n" << WhiteSpace::ReplaceWithCodes(m->msgs[i].text) << "\n"
45                 :
46                 out << m->msgs[i].msg << "\n" << m->msgs[i].wparam << "\n" << m->msgs[i].lparam << "\n";
47
48         }
49
50
51     }
52     else return false;
53
54     return true;
55 }
56
57 inline bool ReadMacro(const string& path, ElephantMacro* m ) {
58
59     string line;
60
61     int msg ;   
62     WPARAM wparam;
63     LPARAM lparam;
64
65     ifstream in(path.c_str() );
66     if ( in.good () ) {
67         while ( !in.eof () ) {
68             std::getline(in,line );
69             if ( line == "-1" ) {
70                 std::getline(in,line );
71                 m->msgs.push_back(MacroMsg(-1,WhiteSpace::ReplaceCodesWithWhite(line ) ) );
72             }
73             else {
74                 msg = atoi(line.c_str() );
75                 std::getline(in,line );
76                 wparam = atoi(line.c_str() );
77                 std::getline(in,line );
78                 lparam = atoi(line.c_str() );
79                 m->msgs.push_back(MacroMsg(msg,wparam,lparam ) );
80             }
81         }
82     }
83     else return false;
84
85     return true;
86 }
87
88 #endif
Note: See TracBrowser for help on using the browser.