Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Operation.cpp
Go to the documentation of this file.
1 
11 #include "stdafx.h"
12 #include "Operation.h"
13 #include "OperationManager.h"
14 
15 using namespace kome::operation;
16 
17 
18 #include <crtdbg.h>
19 #ifdef _DEBUG
20  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
21  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
22 #endif // _DEBUG
23 
24 
25 // constructor
27  m_prevPath = "";
28  m_updatePath = "";
29  m_type = -1;
31  m_descript = "";
32  m_paramString = "";
33 
35  mgr.addOperation( this );
36 
37  // キャンセルされたオペレーションを削除
39 }
40 
41 // destructor
44  mgr.removeOperation( this );
45 }
46 
47 // set operation name
48 void Operation::setOperationName( const char* operationName ){
49  m_operatName = operationName;
50 }
51 
52 // get operation name
54  return m_operatName.c_str();
55 }
56 
57 // set short name
58 void Operation::setShortName( const char* shortName ){
59  m_shortName = shortName;
60 }
61 
62 // get short name
64  return m_shortName.c_str();
65 }
66 
67 // set operation type
68 void Operation::setOperationType( int type ){
69  m_type = type;
70 }
71 
72 // get operation type
74  return m_type;
75 }
76 
77 // set description
78 void Operation::setDescription( const char* description ){
79  m_descript = description;
80 }
81 
82 // get description
84  if( m_descript.empty() ){ // @date 2013.09.17 <Mod> M.Izumi
86  }
87  return m_descript.c_str();
88 }
89 
90 // set target sample
92  m_targetSample = sample;
93 }
94 
95 // get target sample
97  return m_targetSample;
98 }
99 
100 // set parameter string
101 void Operation::setParametersString( const char* parameter ){
102  onSetParametersString( parameter );
103 }
104 
105 // get parameter string
107  m_paramString = "";
108  m_paramString = "\"";
110  m_paramString +="\"";
111 
112  return m_paramString.c_str();
113 }
114 
115 // load condition
116 void Operation::loadCondition(boost::function< int ( void*, int ) > readFun ){
117  onLoadCondition( readFun );
118 }
119 
120 // save condition
121 void Operation::saveCondition( boost::function< int ( void*, int ) > writeFun ){
122  onSaveCondition( writeFun );
123 }
124 
125 // execute
127  bool ret = false;
128 
130  if( getOperationType() == Operation::TYPE_INPUT ||
131  getOperationType() == Operation::TYPE_OUTPUT ){
132 
133  // execute
134  ret = onExecute();
135  }else{
136  // -----
137  // Undo
138  // -----
139  m_prevPath = optMgr.getPreviousDataFilePath( this );
140  FILE* prevfp = fileopen( m_prevPath.c_str(), "wb" );
141 
142  kome::core::FileAccessor prev_acc( prevfp );
143  saveCondition( boost::bind( &kome::core::DataAccessor::write, &prev_acc, _1, _2 ) );
144 
145  fclose( prevfp );
146 
147  // Previous Data File Path
148  setPrevFilePath( m_prevPath.c_str() );
149 
150  // execute
151  ret = onExecute();
152 
153  // -----
154  // Redo
155  // -----
156  m_updatePath = optMgr.getUpdateDataFilePath( this );
157  FILE* updatefp = fileopen( m_updatePath.c_str(), "wb" );
158 
159  kome::core::FileAccessor update_acc( updatefp );
160  saveCondition( boost::bind( &kome::core::DataAccessor::write, &update_acc, _1, _2 ) );
161 
162  fclose( updatefp );
163 
164  // Update Data File Path
165  setUpdateFilePath( m_updatePath.c_str() );
166  }
167  if( ret ){
168  // Finished
169  optMgr.moveToFinished( this );
170  }
171  return ret;
172 }
173 
174 // get previous data file path
176  return m_prevPath;
177 }
178 
179 // set previous data file path
180 void Operation::setPrevFilePath( const char* strPath ){
181  m_prevPath = strPath;
182 }
183 
184 // get update data file path
186  return m_updatePath;
187 }
188 
189 // set update data file path
190 void Operation::setUpdateFilePath( const char* strPath ){
191  m_updatePath = strPath;
192 }
kome::objects::Sample * getTargetSample()
gets target sample objects
Definition: Operation.cpp:96
void setOperationName(const char *operationName)
sets operation name
Definition: Operation.cpp:48
void addOperation(Operation *operation)
add managed operation
const char * getShortName()
gets short name
Definition: Operation.cpp:63
const char * getDescription()
gets description
Definition: Operation.cpp:83
file accessor class
Definition: FileAccessor.h:26
virtual void onSaveCondition(boost::function< int(void *, int) > writeFun)=0
save the current state with respect to search engine operations
void setShortName(const char *shortName)
sets short name
Definition: Operation.cpp:58
kome::objects::Sample * m_targetSample
Definition: Operation.h:50
virtual std::string onGetDescription()=0
get discription
void moveToFinished(Operation *operation)
moves the operation to the finished queue.
sample information management class
Definition: Sample.h:34
implements of GridEmailTextCtrl class
implements of GridEmailTextCtrl class
virtual std::string onGetParametersString()=0
get parameters string
static OperationManager & getInstance()
get operation manager object (This is the only object.)
std::string getPrevFilePath()
gets previouse data file path
Definition: Operation.cpp:175
const char * getPreviousDataFilePath(Operation *operation)
gets the file path to save the previous status
virtual bool onExecute()=0
execute operation
void setOperationType(int type)
sets operation type
Definition: Operation.cpp:68
int getOperationType()
gets operation type
Definition: Operation.cpp:73
void setParametersString(const char *parameter)
sets parameters string
Definition: Operation.cpp:101
void setPrevFilePath(const char *strPath)
sets previouse data file path
Definition: Operation.cpp:180
virtual void onSetParametersString(const char *strParam)=0
set parameters string
const char * getParametersString()
gets operaton parameters string
Definition: Operation.cpp:106
void saveCondition(boost::function< int(void *, int) > writeFun)
save the current state with engine operations
Definition: Operation.cpp:121
#define NULL
Definition: CoreMacros.h:18
std::string m_updatePath
Definition: Operation.h:59
std::string m_paramString
Definition: Operation.h:53
std::string getUpdateFilePath()
gets udate data file path
Definition: Operation.cpp:185
void removeOperation(Operation *operation)
remove managed operation
FILE * fileopen(const char *path, const char *mode)
opens file
const char * getOperationName()
gets operation name
Definition: Operation.cpp:53
virtual ~Operation()
destructor
Definition: Operation.cpp:42
void clearCanceledOperation()
clears canceled operations
virtual int write(void *addr, int size)=0
writes data (abstract method)
bool execute()
execute operation
Definition: Operation.cpp:126
void loadCondition(boost::function< int(void *, int) > readFun)
load the saved state with operations
Definition: Operation.cpp:116
void setUpdateFilePath(const char *strPath)
sets udate data file path
Definition: Operation.cpp:190
const char * getUpdateDataFilePath(Operation *operation)
the file path to save the update status
void setDescription(const char *description)
sets description
Definition: Operation.cpp:78
operation management class
void setTargetSample(kome::objects::Sample *sample)
sets target sample objects
Definition: Operation.cpp:91
std::string m_operatName
Definition: Operation.h:38
virtual void onLoadCondition(boost::function< int(void *, int) > readFun)=0
load the saved state with respect to to search engine operations