source: pacpustutorials/solutions/project_exercises/plugin_exercise_1/component_fizzbuzz/FizzBuzz.cpp

Last change on this file was 11, checked in by DHERBOMEZ Gérald, 9 years ago

update solutions of tutorials

File size: 3.8 KB
Line 
1// *********************************************************************
2//
3// created: 2015/09/18
4// filename: FizzBuzz.cpp
5//
6// author: Gerald Dherbomez
7// Copyright Heudiasyc (c) UMR UTC/CNRS 7253
8//
9// license: CECILL-C
10//
11// version: $Id: $
12//
13// brief: Pacpus template component source file
14//
15// *********************************************************************
16
17#include "Pacpus/kernel/ComponentFactory.h"
18#include "Pacpus/kernel/DbiteFileTypes.h"
19
20#include "FizzBuzz.h"
21
22using namespace pacpus;
23
24
25////////////////////////////////////////////////////////////////////////////////
26/// Construct the factory
27static ComponentFactory<FizzBuzz> sFactory("FizzBuzz");
28
29
30
31
32/************************************************************************/
33/* Constructor
34/************************************************************************/
35FizzBuzz::FizzBuzz(QString name)
36 : ComponentBase(name)
37{
38
39}
40
41
42/************************************************************************/
43/* Destructor
44/************************************************************************/
45FizzBuzz::~FizzBuzz()
46{
47
48}
49
50
51/************************************************************************/
52/* Start function, called by the ComponentManager when a start()
53/* command is received
54/************************************************************************/
55void FizzBuzz::startActivity()
56{
57 // if you add an ouput, uncomment the line
58 // out1_ = getTypedOutput<int, FizzBuzz>("value");
59
60 LOG_INFO("FizzBuzz started!");
61
62 // Algo
63 for (counter_ = 1 ; counter_ <= 100 ; counter_++)
64 {
65 if ( counter_ % 3 && counter_ % 5 )
66 std::cout << counter_;
67 else
68 {
69 if (!(counter_ % 3))
70 std::cout << "Fizz";
71 if (!(counter_ % 5))
72 std::cout << "Buzz";
73 }
74 std::cout << std::endl;
75 }
76
77}
78
79
80/************************************************************************/
81/* Stop function, called by the ComponentManager when a stop()
82/* command is received
83/************************************************************************/
84void FizzBuzz::stopActivity()
85{
86 LOG_INFO("FizzBuzz stopped!");
87}
88
89
90/************************************************************************/
91/* Called by the framework at initialization
92/************************************************************************/
93void FizzBuzz::addInputs()
94{
95 // uncomment to add an input
96 // addInput<int, FizzBuzz>("value", &FizzBuzz::processInput);
97}
98
99
100/************************************************************************/
101/* Called by the framework at initialization
102/************************************************************************/
103void FizzBuzz::addOutputs()
104{
105 // empty: no output
106 // addOutput<int, ProducerExample>("value");
107}
108
109
110
111/************************************************************************/
112/* Example function that produces an output
113/************************************************************************/
114// void FizzBuzz::produceOutput()
115// {
116// int val = 12;
117// checkedSend(out1_, val);
118// }
119
120
121/************************************************************************/
122/* Example function that processes an input
123/************************************************************************/
124// void processInput(const int& value)
125// {
126//
127// }
128
129
130/************************************************************************/
131/* Configuration of the component, called by the ComponentManager after
132/* the construction of the object
133/************************************************************************/
134ComponentBase::COMPONENT_CONFIGURATION FizzBuzz::configureComponent(XmlComponentConfig config)
135{
136
137 return ComponentBase::CONFIGURED_OK;
138}
139
Note: See TracBrowser for help on using the repository browser.