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
  • Betty 2022-03-25 09:01:05

    An unattainable structure for Chinese films in 50 years.

  • Birdie 2021-10-20 18:59:56

    A commercial film, a traversal drama, saving innocent people from fire and water, and by the way talk about Fengyue, so old-fashioned, such a system, why can it be so touching?

Source Code quotes

  • Max Denoff: [telling a joke to the train passengers] Woman always mess up my last name. I was with a girl the other night and she kept calling me "Getoff." She was like, "Getoff! Getoff!" I'm like, "No, it's Denoff. Denoff." She says, "No, you're fat and you're heavy. Get off!"

  • [last lines]

    Colter Stevens: [to Goodwin] If you're reading this e-mail, then Source Code works even better than you and Dr. Rutledge imagined. You thought you were creating eight minutes of a past event, but you're not. You've created a whole new world. Goodwin, if I'm right, somewhere at the Source Code facility, you have a Captain Colter Stevens waiting to send on a mission. Promise me you'll help him. And when you do, do me a favor. Tell him everything is going to be okay.