initial framework

- page factory class added
- component class and example added
- blog parser added
This commit is contained in:
Rosia E Evans 2023-06-09 15:29:05 +01:00
parent c620254f2b
commit 18fbad5c7d
29 changed files with 382 additions and 0 deletions

BIN
.vs/BlogParser/v17/.suo Normal file

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
BlogParser.aps Normal file

Binary file not shown.

33
BlogParser.cpp Normal file
View file

@ -0,0 +1,33 @@
#include <iostream>
#include "PageFactory.h"
int main()
{
PageFactory* pageFactory = new PageFactory();
pageFactory->buildPage("#Hello world");
std::cout << pageFactory->getPage();
}
/**
* ####### The Plan #######
* We have a factory, this contains a dictionary with a reference to a load of static objects(?)
* This dictionary is built on startup, each object has a start and end tag and the dictionary holds both
* (its given these on build)
* The factory goes through a given text fileand for each character, checks if its in the dictionary,
* if it is we call that object and pass it all the text until its end char. It will then produce
* output html that is stored in the factory as that page.
*
* Main issues with this:
* We cant have components of a page inside each other :(
* We'll deal with this later
*
* Also, are we building this page on each request? if so how does the user request a file that doesnt exist?
* I guess these are questions for oat++ to answer
*/
/*
BIG ISSUE:
we need our identifiers to be char[]'s since we have things like ## which is more than one char.
*/

31
BlogParser.sln Normal file
View file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32901.215
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BlogParser", "BlogParser.vcxproj", "{8691FEF7-3635-4958-8DE1-70B3A0D439E5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Debug|x64.ActiveCfg = Debug|x64
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Debug|x64.Build.0 = Debug|x64
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Debug|x86.ActiveCfg = Debug|Win32
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Debug|x86.Build.0 = Debug|Win32
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Release|x64.ActiveCfg = Release|x64
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Release|x64.Build.0 = Release|x64
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Release|x86.ActiveCfg = Release|Win32
{8691FEF7-3635-4958-8DE1-70B3A0D439E5}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {70669855-DF9B-4D65-9364-ED1AFEACF708}
EndGlobalSection
EndGlobal

144
BlogParser.vcxproj Normal file
View file

@ -0,0 +1,144 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
<ProjectGuid>{8691fef7-3635-4958-8de1-70b3a0d439e5}</ProjectGuid>
<RootNamespace>BlogParser</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v143</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="Shared">
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
<FunctionLevelLinking>true</FunctionLevelLinking>
<IntrinsicFunctions>true</IntrinsicFunctions>
<SDLCheck>true</SDLCheck>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<GenerateDebugInformation>true</GenerateDebugInformation>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="BlogParser.cpp" />
<ClCompile Include="Component.cpp" />
<ClCompile Include="Header.cpp" />
<ClCompile Include="PageFactory.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Component.h" />
<ClInclude Include="ComponentList.h" />
<ClInclude Include="Header.h" />
<ClInclude Include="PageFactory.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

View file

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Filter Include="Source Files">
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
<Extensions>cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
</Filter>
<Filter Include="Header Files">
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
<Extensions>h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd</Extensions>
</Filter>
<Filter Include="Resource Files">
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
</Filter>
<Filter Include="Source Files\Components">
<UniqueIdentifier>{99991709-bfaf-4089-ba9a-66292f776f3e}</UniqueIdentifier>
</Filter>
<Filter Include="Header Files\Components">
<UniqueIdentifier>{c445922c-4e2c-45ee-91eb-0f1d01e4d42c}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="BlogParser.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="PageFactory.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Component.cpp">
<Filter>Source Files\Components</Filter>
</ClCompile>
<ClCompile Include="Header.cpp">
<Filter>Source Files\Components</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="PageFactory.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ComponentList.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Component.h">
<Filter>Header Files\Components</Filter>
</ClInclude>
<ClInclude Include="Header.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

4
BlogParser.vcxproj.user Normal file
View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup />
</Project>

1
Component.cpp Normal file
View file

@ -0,0 +1 @@
#include "Component.h"

10
Component.h Normal file
View file

@ -0,0 +1,10 @@
#pragma once
class Component
{
public:
char startIdentifier;
char endIdentifier;
virtual std::string generateHTML(std::string markDown);
};

7
ComponentList.h Normal file
View file

@ -0,0 +1,7 @@
#pragma once
#include <vector>
#include "Component.h"
std::vector<Component> componentList = {
};

6
Header.cpp Normal file
View file

@ -0,0 +1,6 @@
#include "Header.h"
std::string Header::generateHTML(std::string markDown)
{
return "<h1>" + markDown + "</h1>";
}

8
Header.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#include <string>
#include "Component.h"
class Header : public Component
{
std::string generateHTML(std::string markDown);
};

48
PageFactory.cpp Normal file
View file

@ -0,0 +1,48 @@
#include "PageFactory.h"
PageFactory::PageFactory()
{
// generate component dictionary
for (Component component : componentList)
{
componentDictionary.push_back({ component.startIdentifier, &component });
}
}
void PageFactory::buildPage(std::string markDown)
{
Component* currentComponent;
bool readingChunk = false;
std::string currentChunk;
/*
Something worth noting here is that we dont pass the start
and end identifier into the component.
*/
for (char character : markDown)
{
if (readingChunk)
{
if (character == currentComponent->endIdentifier)
{
finalPage = currentComponent->generateHTML(currentChunk);
readingChunk = false;
currentChunk = "";
}
else
{
currentChunk.push_back(character);
}
}
else
{
// search dictionary to find a component
// if found, get component, set readingChunk to true
}
}
}
std::string PageFactory::getPage()
{
return finalPage;
}

25
PageFactory.h Normal file
View file

@ -0,0 +1,25 @@
#pragma once
#include <string>
#include <string.h>
#include "Component.h"
#include "ComponentList.h"
#include <vector>
class PageFactory
{
struct ComponentDictItem
{
char identifier;
Component* component;
};
std::vector<ComponentDictItem> componentDictionary;
std::string finalPage;
public:
PageFactory();
void buildPage(std::string markDown);
std::string getPage();
};

14
resource.h Normal file
View file

@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by BlogParser.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif