Common System 0.2.0
Common interfaces and patterns for system integration
Loading...
Searching...
No Matches
calculation_job Class Reference
Inheritance diagram for calculation_job:
Inheritance graph
Collaboration diagram for calculation_job:
Collaboration graph

Public Member Functions

 calculation_job (int value, std::atomic< int > &result)
 
VoidResult execute () override
 Execute the job.
 
std::string get_name () const override
 Get the name of the job (for logging/debugging)
 
int get_priority () const override
 Get the priority of the job (higher = more important)
 
- Public Member Functions inherited from kcenon::common::interfaces::IJob
virtual ~IJob ()=default
 
virtual ~IJob ()=default
 

Private Attributes

int value_
 
std::atomic< int > & result_
 

Detailed Description

Example job implementation

Examples
executor_example.cpp.

Definition at line 217 of file executor_example.cpp.

Constructor & Destructor Documentation

◆ calculation_job()

calculation_job::calculation_job ( int value,
std::atomic< int > & result )
inline
Examples
executor_example.cpp.

Definition at line 219 of file executor_example.cpp.

220 : value_(value), result_(result) {}
std::atomic< int > & result_

Member Function Documentation

◆ execute()

VoidResult calculation_job::execute ( )
inlineoverridevirtual

Execute the job.

Returns
VoidResult indicating success or failure

Implements kcenon::common::interfaces::IJob.

Examples
executor_example.cpp.

Definition at line 222 of file executor_example.cpp.

222 {
223 try {
224 // Simulate some work
225 std::this_thread::sleep_for(10ms);
226 result_ += value_ * value_;
227 return VoidResult(std::monostate{});
228 } catch (const std::exception& e) {
229 return VoidResult(
230 error_info(1, e.what(), "calculation_job"));
231 }
232 }
Result< std::monostate > VoidResult
Specialized Result for void operations.
Definition core.h:70
Standard error information used by Result<T>.
Definition core.cppm:106

References result_, and value_.

◆ get_name()

std::string calculation_job::get_name ( ) const
inlineoverridevirtual

Get the name of the job (for logging/debugging)

Returns
Job name

Implements kcenon::common::interfaces::IJob.

Examples
executor_example.cpp.

Definition at line 234 of file executor_example.cpp.

234 {
235 return "calculation_job_" + std::to_string(value_);
236 }

References value_.

◆ get_priority()

int calculation_job::get_priority ( ) const
inlineoverridevirtual

Get the priority of the job (higher = more important)

Returns
Job priority (default: 0)

Implements kcenon::common::interfaces::IJob.

Examples
executor_example.cpp.

Definition at line 238 of file executor_example.cpp.

238 {
239 return value_; // Higher values = higher priority
240 }

References value_.

Member Data Documentation

◆ result_

std::atomic<int>& calculation_job::result_
private
Examples
executor_example.cpp.

Definition at line 244 of file executor_example.cpp.

Referenced by execute().

◆ value_

int calculation_job::value_
private
Examples
executor_example.cpp.

Definition at line 243 of file executor_example.cpp.

Referenced by execute(), get_name(), and get_priority().


The documentation for this class was generated from the following file: