What kind of story does the source code tell

Marc 2022-03-14 14:12:21

After thinking about it, the plot of the source code can be roughly represented by the following code

#include

#include

#include

#include

#include

#include

using namespace std;

struct World;

struct Person

{

std::vector m_Memories;

std::string m_Name;

World *m_pWorld = nullptr;

Person(const std::string &name)

: m_Name(name)

{}

};

int g_TrainThreadInited = 0;

int g_TrainThreadCrashed = 0;

int g_TryTimes = 0;

Person g_p1("Stevens"), g_p2("Sean");

struct World

{

Person *m_pMainCharacter = nullptr;

World(Person *character)

: m_pMainCharacter(character)

{}

void SadStory()

{

cout << "Boom !" << endl;

}

void HappyStory()

{

cout << "Mua !" << endl;

}

};

void TrainThread(World *pWorld)

{

try

{

if (g_TryTimes <8)

{

pWorld->SadStory();

++g_TryTimes;

throw std::exception("Boom !");

}

else

pWorld->HappyStory();

}

catch (std::exception &e)

{

pWorld->m_pMainCharacter->m_Memories.push_back(e.what());

g_TrainThreadCrashed = 1;

}

}

int main()

{

std::shared_ptr threadptr;

for (;;)

{

if (!g_TrainThreadInited || g_TrainThreadCrashed)

{

World w(&g_p2);

g_p1.m_pWorld = &w;

w.m_pMainCharacter = &g_p1;

threadptr.reset(new thread (TrainThread, &w));

threadptr->detach();

if (!g_TrainThreadInited)

g_TrainThreadInited = 1;

if (g_TrainThreadCrashed)

g_TrainThreadCrashed = 0;

}

}

return 0;

}

View more about Source Code reviews

Extended Reading

Source Code quotes

  • Colter Stevens: The explosion came from behind me.

  • Colter Stevens: You seem concerned about the time. What are you late for?

    Max Denoff: I'm on my way to an asshole festival. I hear you're headlining.

    Colter Stevens: Oh, that's funny. What are you, a comedian?

    Christina Warren: Yeah. He is a comedian.