Stock Market Simulator main 97bb929
A game that provides a realistic stock buying experience with unpredictable trends to test investment strategies.
Loading...
Searching...
No Matches
Stock_event Struct Reference

The data structure of an event that will be applied to the stocks. More...

#include "events.h"

Collaboration diagram for Stock_event:

Public Member Functions

bool operator== (const Stock_event &other) const
 Overload the == operator to compare two Stock_event.
 

Public Attributes

unsigned int category
 
unsigned int duration
 Number of rounds the event will last.
 
unsigned int event_id
 The id of the event.
 
std::map< stock_modifiers, double > modifiers
 Stores the stock_modifiers that the event applies.
 
std::vector< unsigned int > mutually_exclusive_events
 A list of event_ids that this event is mutually exclusive with.
 
unsigned int probability_permille
 0 to 1000, so 114 means 11.4%
 
std::string text
 The text that will be displayed to the player.
 
event_type type_of_event
 The type of event: Apply to all stocks, in one category or randomly?
 

Friends

std::ostream & operator<< (std::ostream &outputstream, const Stock_event &event)
 Serialize the event as std::ostream object.
 
std::istream & operator>> (std::istream &inputstream, Stock_event &event)
 Deserialize the event from a std::istream object.
 

Detailed Description

The data structure of an event that will be applied to the stocks.

Note
For more information about how to write your own events, visit the documentation of the events.h file.

Definition at line 104 of file events.h.

Member Function Documentation

◆ operator==()

bool Stock_event::operator== ( const Stock_event & other) const
inline

Overload the == operator to compare two Stock_event.

Definition at line 135 of file events.h.

135 {
136 return event_id == other.event_id && text == other.text &&
138 type_of_event == other.type_of_event && category == other.category &&
139 modifiers == other.modifiers;
140 }
event_type type_of_event
The type of event: Apply to all stocks, in one category or randomly?
Definition events.h:127
unsigned int probability_permille
0 to 1000, so 114 means 11.4%
Definition events.h:123
unsigned int category
Definition events.h:129
std::map< stock_modifiers, double > modifiers
Stores the stock_modifiers that the event applies.
Definition events.h:132
std::string text
The text that will be displayed to the player.
Definition events.h:116
unsigned int event_id
The id of the event.
Definition events.h:110

References category, event_id, modifiers, probability_permille, text, and type_of_event.

Friends And Related Symbol Documentation

◆ operator<<

std::ostream & operator<< ( std::ostream & outputstream,
const Stock_event & event )
friend

Serialize the event as std::ostream object.

Parameters
outputstreamThe std::ostream object to write the data.
eventThe event object to get the data from.
Returns
A std:ostream object contains all the data of the event.
// Create a event object by calling the constructor
// Print the data of the event.
std::cout << event << std::endl;
The data structure of an event that will be applied to the stocks.
Definition events.h:104

Definition at line 154 of file events.h.

155 {
156 outputstream << event.event_id << " ";
157 for (unsigned int i = 0; i < event.mutually_exclusive_events.size(); i++) {
158 outputstream << event.mutually_exclusive_events[i] << " ";
159 }
160 outputstream << ";" << event.text << ";" << event.duration << " "
161 << event.probability_permille << " " << event.type_of_event
162 << " " << event.category << " ";
163 for (const auto & modifier : event.modifiers) {
164 outputstream << modifier.second << " ";
165 }
166 return outputstream;
167 }

◆ operator>>

std::istream & operator>> ( std::istream & inputstream,
Stock_event & event )
friend

Deserialize the event from a std::istream object.

Parameters
inputstreamThe std::istream object to read the data.
eventThe event object to store the data.
Returns
A std:istream object contains all the data of the event.

Definition at line 175 of file events.h.

176 {
177 // fix the bug that mutually_exclusive_events is not read correctly
178 inputstream >> event.event_id;
179 std::string _mutually_exclusive_events;
180 std::getline(inputstream, _mutually_exclusive_events, ';');
181 std::istringstream mutually_exclusive_events_stream(
182 _mutually_exclusive_events);
183 unsigned int temp_id;
184 while (mutually_exclusive_events_stream >> temp_id) {
185 event.mutually_exclusive_events.emplace_back(temp_id);
186 }
187 std::getline(inputstream, event.text, ';');
188 unsigned int temp_type;
189 inputstream >> event.duration >> event.probability_permille >> temp_type >>
190 event.category;
191 event.type_of_event = static_cast<event_type>(temp_type);
192 inputstream >> event.modifiers[standard_deviation] >>
193 event.modifiers[mean] >> event.modifiers[lower_limit] >>
194 event.modifiers[upper_limit];
195 return inputstream;
196 }
@ upper_limit
The upper limit of the stock price percentage change.
Definition events.h:48
@ standard_deviation
Amount of variation of the stock price percentage change.
Definition events.h:32
@ mean
The expectation of the stock price percentage change.
Definition events.h:36
@ lower_limit
The lower limit of the stock price percentage change.
Definition events.h:42
event_type
The type of event that will be applied to the stocks.
Definition events.h:88

Member Data Documentation

◆ category

unsigned int Stock_event::category

Definition at line 129 of file events.h.

Referenced by operator==(), and Stock::setup_STOCK_SPLIT_EVENT().

◆ duration

unsigned int Stock_event::duration

Number of rounds the event will last.

If the event has duration <= 0 then it will be removed.

Definition at line 120 of file events.h.

◆ event_id

unsigned int Stock_event::event_id

The id of the event.

This is still required for checking, despite the fact that we are using a vector.

Definition at line 110 of file events.h.

Referenced by Stock::can_add_event(), and operator==().

◆ modifiers

std::map<stock_modifiers, double> Stock_event::modifiers

Stores the stock_modifiers that the event applies.

Definition at line 132 of file events.h.

Referenced by operator==().

◆ mutually_exclusive_events

std::vector<unsigned int> Stock_event::mutually_exclusive_events

A list of event_ids that this event is mutually exclusive with.

Definition at line 113 of file events.h.

◆ probability_permille

unsigned int Stock_event::probability_permille

0 to 1000, so 114 means 11.4%

Definition at line 123 of file events.h.

Referenced by operator==().

◆ text

std::string Stock_event::text

The text that will be displayed to the player.

Definition at line 116 of file events.h.

Referenced by new_events_next_round(), operator==(), and Stock::setup_STOCK_SPLIT_EVENT().

◆ type_of_event

event_type Stock_event::type_of_event

The type of event: Apply to all stocks, in one category or randomly?

Definition at line 127 of file events.h.

Referenced by operator==().


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