Verbindung von GDE mit unserem Projekt Hazard

im Ordner GDE_3_Hazard. Ab nun koennen wir weiter in diesem Ordner
programmieren.
This commit is contained in:
gaeltp3 2013-11-28 16:08:16 +01:00
parent 265c45b215
commit 7a52e186d9
79 changed files with 7345 additions and 210 deletions

53
GDE_3_2008/Cell.cpp Normal file
View file

@ -0,0 +1,53 @@
#include "stdafx.h"
#include <string>
#include <vector>
#include "PrimImplikantCollection.h"
#include "Cell.h"
using namespace std;
extern uint dimension;
void Cell::refresh(PrimImplikantCollection* &globalPIC)
{
this->primImplikanten = globalPIC->primImplikantenAt(index);
}
vector<Cell*>* Cell::getNeighbors(vector<Cell*> &allCells)
{
vector<Cell*>* neighbors = new vector<Cell*>();
uint j = 1;
for (unsigned char i = 0; i < dimension; i++)
{
neighbors->push_back(allCells[this->index ^ j]);
j <<= 1;
}
return neighbors;
}
vector<Cell*>* Cell::getHazards(vector<Cell*> &allCells)
{
vector<Cell*>* hazardous = new vector<Cell*>();
vector<Cell*>* neighbors = this->getNeighbors(allCells);
for (vector<Cell*>::iterator neighbor = neighbors->begin(); neighbor < neighbors->end(); neighbor++)
{
if ((*neighbor)->value == false)
continue;
if ((*neighbor)->hasOneOfThose(this->primImplikanten) == false)
hazardous->push_back(*neighbor);
}
delete neighbors;
return hazardous;
}
bool Cell::hasOneOfThose(PrimImplikantCollection &foreignPic)
{
for (uint i = 0; i < foreignPic.size(); i++)
if (this->primImplikanten.contains(foreignPic[i]))
return true;
return false;
}

30
GDE_3_2008/Cell.h Normal file
View file

@ -0,0 +1,30 @@
#include <string>
#include <vector>
#include "PrimImplikantCollection.h"
using namespace std;
#ifndef CELL
#define CELL
class Cell {
public:
bool value;
unsigned int index;
vector<Cell*>* getNeighbors(vector<Cell*> &allCells); // returns numElements Cells
vector<Cell*>* getHazards(vector<Cell*> &allCells); // returns the neighbor Cells which are hazardous
bool hasOneOfThose(PrimImplikantCollection &foreignPIC);
void refresh(PrimImplikantCollection* &globalPIC); // refreshes the local primImplikantCollection
Cell(unsigned int index, PrimImplikantCollection* &globalPIC)
{
this->index = index;
this->refresh(globalPIC);
this->value = this->primImplikanten.size() > 0;
}
PrimImplikantCollection primImplikanten;
};
#endif

View file

@ -1,77 +1,350 @@
#include <string>
#include <vector>
#include<map>
#include "stdafx.h"
#include "Cparser.h"
#pragma warning(disable:4786)
#include <vector>
#include <string>
#include <map>
#include "PrimImplikantCollection.h"
#include "CParser.h"
using namespace std;
#define Getc(s) getc(s)
#define Ungetc(c) ungetc(c,IP_Input)
#define Getc(s) getc(s)
#define Ungetc(c) {ungetc(c,IP_Input); ugetflag=1;}
/* Lexical analyser states. */
extern unsigned int dimension;
extern unsigned int numElements;
extern bool KNF;
enum lexstate{L_START,L_INT,L_IDENT};
// Adds a character to the string value
void CParser::PushString(char c)
{
yylval.s += c;
}
//------------------------------------------------------------------------
void CParser::Load_tokenentry(string str,int index)
{
IP_Token_table[str]=index;
IP_revToken_table[index]=str;
}
void CParser::IP_init_token_table()
{
Load_tokenentry("STRING1",STRING1);
Load_tokenentry("IDENTIFIER",IDENTIFIER);
Load_tokenentry("INTEGER1",INTEGER1);
Load_tokenentry("Variables",VARIABLES);
Load_tokenentry("Terms",TERMS);
}
//------------------------------------------------------------------------
int Cparser::yylex(){
int c;
lexstate s;
void CParser::pr_tokentable()
{
typedef map<string,int>::const_iterator CI;
const char* buf;
for(s=L_START, yytext="";1;){
c= Getc(IP_Input);
yytext=yytext+(char)c;
switch (s){
case L_START:
if(isdigit(c)){
if((char)c!='x'){
s=L_INT;
}else{
Ungetc(c);
yytext=yytext.substr(0,yytext.size()-1);
yytext1+='1';
yytext+='0';// ab hier gut überlegen falls x auftritte
break;
}
}else if (isspace(c)||isalpha(c)){
s=L_IDENT;
}else if(c==EOF){
return 0;
}else if (c=='\n'){ LineNumber+=1;
}else { return 0;
}
break;
case L_INT:
if(isdigit(c)){ break;
}else {
Ungetc(c);
yylval.s=yytext.substr(0,yytext.size()-1);
}
break;
case L_IDENT:
if(isalpha(c)){
yylval.s=yytext.substr(0,yytext.size()-1);
yylval.i=atoi(yylval.s.c_str());
yytext="";
}
break;
default:
printf("*** Fatal Error!!!!!*** Wrong case label in yylex\n");
}
printf( "Symbol Table ---------------------------------------------\n");
for(CI p=IP_Token_table.begin(); p!=IP_Token_table.end(); ++p){
buf = p->first.c_str();
printf(" key:%s", buf);
printf(" val:%d\n", p->second);;
}
}
//------------------------------------------------------------------------
int CParser::yyparse(PrimImplikantCollection* &pic, vector<string>* &variables)
{
bool KNFset = false;
int tok;
if(prflag)fprintf(IP_List,"%5d ", IP_LineNumber);
/*
* Go parse things!
*/
parsestate pState = P_START;
while ((tok=yylex())!=0){
switch (pState)
{
case P_START:
switch (tok)
{
case VARIABLES:
pState = P_VARIABLES;
break;
case TERMS:
pState = P_TERMS_KEY;
break;
}
break;
case P_VARIABLES:
switch(tok)
{
case IDENTIFIER:
fprintf(IP_List, "Variable %s\n", yylval.s.c_str());
variables->push_back(yylval.s.c_str());
break;
case TERMS:
fprintf(IP_List, "\n", yylval.s.c_str());
pState = P_TERMS_KEY;
break;
}
break;
case P_TERMS_KEY:
switch(tok)
{
case STRING1:
fprintf(IP_List, "Term Key %s\n", yylval.s.c_str());
pic->add(yylval.s.c_str());
break;
case INTEGER1:
fprintf(IP_List, "Term Key %d\n", (unsigned int)yylval.i);
pic->add(yylval.i);
break;
case (int)'>':
pState = P_TERMS_VALUE;
break;
case VARIABLES:
pState = P_VARIABLES;
break;
}
break;
case P_TERMS_VALUE:
if (tok == INTEGER1)
{
if (!KNFset)
{
KNF = (yylval.i == 0);
KNFset = true;
}
else if ((yylval.i == 0) ^ KNF)
{
fprintf(IP_Error, "*** FATAL ERROR *** You can only define either KNF or DNF!\n");
fprintf(IP_Error, "In line %3d: %s>%i\n", (int)IP_LineNumber, pic->back()->name.c_str(), yylval.i);
fprintf(IP_Error, "In line %3d: Defined was: %s, but now shall be changed to %s\n\n", (int)IP_LineNumber, KNF ? "KNF" : "DNF", KNF ? "DNF" : "KNF");
printf("*** FATAL ERROR *** You can only define either KNF or DNF!\n");
return 1;
}
fprintf(IP_List, "Term Value %d\n\n",yylval.i);
pState = P_TERMS_KEY;
}
break;
}
}
dimension = variables->size();
numElements = (unsigned int)pow(2.0f, (int)dimension);
return 0;
}
//------------------------------------------------------------------------
/*
* Parse Initfile:
*
* This builds the context tree and then calls the real parser.
* It is passed two file streams, the first is where the input comes
* from; the second is where error messages get printed.
*/
void CParser::InitParse(FILE *inp,FILE *err,FILE *lst)
{
/*
* Set up the file state to something useful.
*/
IP_Input = inp;
IP_Error = err;
IP_List = lst;
IP_LineNumber = 1;
ugetflag=0;
/*
* Define both the enabled token and keyword strings.
*/
IP_init_token_table();
}
//------------------------------------------------------------------------
/*
* yyerror:
*
* Standard error reporter, it prints out the passed string
* preceeded by the current filename and line number.
*/
void CParser::yyerror(char *ers)
{
fprintf(IP_Error,"line %d: %s\n",IP_LineNumber,ers);
}
//------------------------------------------------------------------------
int CParser::IP_MatchToken(string &tok)
{
int retval;
if( IP_Token_table.find(tok) != IP_Token_table.end()){
retval = (IP_Token_table[tok]);
}else{
retval = (0);
}
return retval;
}
//------------------------------------------------------------------------
/*
* yylex:
*
*/
int CParser::yylex()
{
//Locals
int c;
lexstate s;
/*
* Keep on sucking up characters until we find something which
* explicitly forces us out of this function.
*/
yytext = "";
yylval.s = "";
yylval.i = 0;
for (s = L_START; 1;){
c = Getc(IP_Input);
yytext = yytext + (char)c;
if(!ugetflag) {
if(c != EOF)if(prflag)fprintf(IP_List,"%c",c);
}else ugetflag = 0;
switch (s){
//Starting state, look for something resembling a token.
case L_START:
yytext = (char)c;
if (isdigit(c)){
s = L_INT;
}else if (isalpha(c) || c == '\\' ){
s = L_IDENT;
}else if (isspace(c)){
if (c == '\n'){
IP_LineNumber += 1;
if(prflag)
fprintf(IP_List,"%5d ",(int)IP_LineNumber);
s = L_START;
yytext = "";
}
}else if (c == '/'){
yytext = "";
s = L_COMMENT;
}else if (c == '"'){
s = L_STRING;
}else if (c == EOF){
return ('\0');
}else{
s = L_START;
yytext = "";
return (c);
}
break;
case L_COMMENT:
if (c == '/')
s = L_LINE_COMMENT;
else if(c == '*')
s = L_TEXT_COMMENT;
else{
Ungetc(c);
return('/'); /* its the division operator not a comment */
}
break;
case L_LINE_COMMENT:
if ( c == '\n'){
s = L_START;
Ungetc(c);
}
yytext = "";
break;
case L_TEXT_COMMENT:
if ( c == '\n'){
IP_LineNumber += 1;
}else if (c == '*')
s = L_END_TEXT_COMMENT;
yytext = "";
break;
case L_END_TEXT_COMMENT:
if (c == '/'){
s = L_START;
}else{
s = L_TEXT_COMMENT;
}
yytext = "";
break;
/*
* Suck up the integer digits.
*/
case L_INT:
if (isdigit(c)){
break;
}else {
Ungetc(c);
yylval.s = yytext.substr(0,yytext.size()-1);
yylval.i = atoi(yylval.s.c_str());
return (INTEGER1);
}
break;
/*
* Grab an identifier, see if the current context enables
* it with a specific token value.
*/
case L_IDENT:
if (isalpha(c) || isdigit(c) || c == '_')
break;
Ungetc(c);
yytext = yytext.substr(0,yytext.size()-1);
yylval.s = yytext;
if (c = IP_MatchToken(yytext)){
return (c);
}else{
return (IDENTIFIER);
}
/*
* Suck up string characters but once resolved they should
* be deposited in the string bucket because they can be
* arbitrarily long.
*/
case L_STRING2:
s = L_STRING;
if(c == '"'){
PushString((char)c);
}else{
if(c == '\\'){
PushString((char)c);
}else{
PushString((char)'\\');
PushString((char)c);
}
}
break;
case L_STRING:
if (c == '\n')
IP_LineNumber += 1;
else if (c == '\r')
;
else if (c == '"' || c == EOF){
return (STRING1);
} else if(c=='\\'){
s = L_STRING2;
//PushString((char)c);
}else
PushString((char)c);
break;
default:
fprintf(IP_Error, "*** FATAL ERROR *** Wrong case label in yylex\n");
fprintf(IP_Error, "In line %3d: state %i", IP_LineNumber, s);
printf("***Fatal Error*** Wrong case label in yylex\n");
}
}
}

View file

@ -1,49 +1,58 @@
#ifndef CPARSER
#define CPARSER
// k7scan1.cpp : Definiert den Einsprungpunkt für die Konsolenanwendung.
//
#include "stdafx.h"
#pragma warning(disable:4786)
#include <string>
#include "PrimImplikanten.h"
#include <map>
#include "PrimImplikantCollection.h"
using namespace std;
#define Getc(s) getc(s)
#define Ungetc(c) {ungetc(c,IP_Input); ugetflag=1;}
class Cparser{
private:
PrimImplikant implikant;
/*
* Lexical analyzer states.
*/
enum lexstate{L_START,L_INT,L_IDENT,L_STRING,L_STRING2,
L_COMMENT,L_TEXT_COMMENT,L_LINE_COMMENT,L_END_TEXT_COMMENT};
enum parsestate{P_START,P_VARIABLES,P_TERMS_KEY,P_TERMS_VALUE};
const int STRING1=3;
const int IDENTIFIER=4;
const int INTEGER1=5;
const int VARIABLES=300;
const int TERMS=301;
class CParser
{
public:
string yytext;
string yytext1;
int LineNumber;
struct tyylval{
string s;
int i;
string yytext; //input buffer
struct tyylval{ //value return
string s; //structure
int i;
}yylval;
FILE* IP_Input;
void pr_tokentable();
void load_tokenentry(string s ,int x);
int yylex();
};
FILE *IP_Input; //Input File
FILE *IP_Error; //Error Output
FILE *IP_List; //List Output
int IP_LineNumber; //Line counter
int ugetflag; //checks ungets
int prflag; //controls printing
map<string,int> IP_Token_table; //Tokendefinitions
map<int,string> IP_revToken_table; //reverse Tokendefinitions
#endif
int CParser::yyparse(PrimImplikantCollection* &pic, vector<string>* &variables); //parser
int CParser::yylex(); //lexial analyser
void CParser::yyerror(char *ers); //error reporter
int CParser::IP_MatchToken(string &tok); //checks the token
void CParser::InitParse(FILE *inp,FILE *err,FILE *lst);
void CParser::pr_tokentable(); //test output for tokens
void CParser::IP_init_token_table(); //loads the tokens
void CParser::Load_tokenentry(string str,int index);//load one token
void CParser::PushString(char c); //Used for dtring assembly
CParser(){IP_LineNumber = 1;ugetflag=0;prflag=0;}; //Constructor
};

View file

@ -1,7 +1,13 @@
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GDE_3", "GDE_3.vcxproj", "{B0DC7B0A-75D1-4BF6-9861-3C4056C4AA6B}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Hazard", "..\Hazard\Hazard\Hazard.vcxproj", "{504179E7-6D11-4B2C-9172-3293E8739C3F}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GDE_3_hazard", "..\GDE_3_hazard\GDE_3_hazard.vcxproj", "{FF9E2DB5-8867-4FA2-9019-B42189D87ACA}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@ -12,6 +18,14 @@ Global
{B0DC7B0A-75D1-4BF6-9861-3C4056C4AA6B}.Debug|Win32.Build.0 = Debug|Win32
{B0DC7B0A-75D1-4BF6-9861-3C4056C4AA6B}.Release|Win32.ActiveCfg = Release|Win32
{B0DC7B0A-75D1-4BF6-9861-3C4056C4AA6B}.Release|Win32.Build.0 = Release|Win32
{504179E7-6D11-4B2C-9172-3293E8739C3F}.Debug|Win32.ActiveCfg = Debug|Win32
{504179E7-6D11-4B2C-9172-3293E8739C3F}.Debug|Win32.Build.0 = Debug|Win32
{504179E7-6D11-4B2C-9172-3293E8739C3F}.Release|Win32.ActiveCfg = Release|Win32
{504179E7-6D11-4B2C-9172-3293E8739C3F}.Release|Win32.Build.0 = Release|Win32
{FF9E2DB5-8867-4FA2-9019-B42189D87ACA}.Debug|Win32.ActiveCfg = Debug|Win32
{FF9E2DB5-8867-4FA2-9019-B42189D87ACA}.Debug|Win32.Build.0 = Debug|Win32
{FF9E2DB5-8867-4FA2-9019-B42189D87ACA}.Release|Win32.ActiveCfg = Release|Win32
{FF9E2DB5-8867-4FA2-9019-B42189D87ACA}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
@ -23,11 +23,16 @@
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseOfMfc>Static</UseOfMfc>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Template|Win32'">
<PlatformToolset>v120</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@ -111,12 +116,14 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Cparser.cpp" />
<ClCompile Include="Cell.cpp" />
<ClCompile Include="CParser.cpp" />
<ClCompile Include="GDE_3.cpp" />
<ClCompile Include="GDE_3Doc.cpp" />
<ClCompile Include="GDE_3View.cpp" />
<ClCompile Include="MainFrm.cpp" />
<ClCompile Include="PrimImplikant.cpp" />
<ClCompile Include="PrimImplikantCollection.cpp" />
<ClCompile Include="stdafx.cpp">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
@ -126,15 +133,18 @@
<ClCompile Include="Graphics\Graphicfunctions.cpp" />
<ClCompile Include="Graphics\Shape.cpp" />
<ClCompile Include="Console\Console.cpp" />
<ClCompile Include="Wertetabelle.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Cell.h" />
<ClInclude Include="Cparser.h" />
<ClInclude Include="GDE_3.h" />
<ClInclude Include="GDE_3Doc.h" />
<ClInclude Include="GDE_3View.h" />
<ClInclude Include="Graphics\stdafx.h" />
<ClInclude Include="MainFrm.h" />
<ClInclude Include="PrimImplikant.h" />
<ClInclude Include="PrimImplikantCollection.h" />
<ClInclude Include="PrimImplikanten.h" />
<ClInclude Include="Resource.h" />
<ClInclude Include="stdafx.h" />
<ClInclude Include="User.h" />
@ -145,6 +155,7 @@
<ClInclude Include="Graphics\PointerArray.h" />
<ClInclude Include="Graphics\Shape.h" />
<ClInclude Include="Console\Console.h" />
<ClInclude Include="Wertetabelle.h" />
</ItemGroup>
<ItemGroup>
<None Include="res\GDE_3.ico" />

View file

@ -51,10 +51,19 @@
<ClCompile Include="Console\Console.cpp">
<Filter>Console</Filter>
</ClCompile>
<ClCompile Include="Cell.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="CParser.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="PrimImplikant.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="Cparser.cpp">
<ClCompile Include="PrimImplikantCollection.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
<ClCompile Include="Wertetabelle.cpp">
<Filter>Quelldateien</Filter>
</ClCompile>
</ItemGroup>
@ -101,15 +110,24 @@
<ClInclude Include="Console\Console.h">
<Filter>Console</Filter>
</ClInclude>
<ClInclude Include="PrimImplikantCollection.h">
<ClInclude Include="Graphics\stdafx.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="PrimImplikanten.h">
<ClInclude Include="Cell.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="Cparser.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="PrimImplikant.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="PrimImplikantCollection.h">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="Wertetabelle.h">
<Filter>Headerdateien</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<None Include="res\GDE_3.ico">

View file

@ -67,7 +67,7 @@ void CDib::Load(CFile* pFile) throw(CImageException)
if(m_pBmpFileHeader->bfType != 0x4d42) {
Clear();
pFile->Close();
throw CImageException(_T("Failed to load document"));
throw CImageException("Failed to load document");
} else {
DWORD dwLength;
dwLength = m_pBmpFileHeader->bfOffBits - sizeof(BITMAPFILEHEADER);
@ -98,7 +98,7 @@ void CDib::Create(CBitmap* pBitmap) throw(CImageException)
BITMAP Bitmap;
int rc = pBitmap->GetBitmap(&Bitmap);
if(rc == 0)
throw CImageException(_T("Can't get BITMAP from CBitmap*"));
throw CImageException("Can't get BITMAP from CBitmap*");
int iWidthBytes = ((Bitmap.bmWidth * Bitmap.bmBitsPixel + 15) & ~15) >> 3 ;
DWORD dwImgSize = iWidthBytes * Bitmap.bmHeight;
@ -194,7 +194,7 @@ void CDib::Save(CString fileName) throw(CImageException)
{
CFile file;
if(file.Open(fileName, CFile::modeWrite | CFile::modeCreate) == 0)
throw CImageException(_T("Cannot open a file"));
throw CImageException("Cannot open a file");
Save(&file);
}
@ -219,7 +219,7 @@ void CDib::Draw(CDC* pdc, int x, int y, double scale, DWORD dwROPCode) const thr
int nScanLines = ::StretchDIBits(pdc->GetSafeHdc(), x, y, (int)(GetWidth()*scale) , (int)(GetHeight()*scale), 0, 0, GetWidth(), GetHeight(),
m_pDibBits, m_pBmpInfo, DIB_RGB_COLORS, dwROPCode);
if(nScanLines == GDI_ERROR)
throw CImageException(_T("CDib::Draw exception"));
throw CImageException("CDib::Draw exception");
}
void CDib::Draw(CDC* pdc, int x, int y, int width, int height, DWORD dwROPCode) const throw(CImageException) {
@ -228,7 +228,7 @@ void CDib::Draw(CDC* pdc, int x, int y, int width, int height, DWORD dwROPCode)
int nScanLines = ::StretchDIBits(pdc->GetSafeHdc(), x, y, width , height, 0, 0, GetWidth(), GetHeight(),
m_pDibBits, m_pBmpInfo, DIB_RGB_COLORS, dwROPCode);
if(nScanLines == GDI_ERROR)
throw CImageException(_T("CDib::Draw exception"));
throw CImageException("CDib::Draw exception");
}
COLORREF CDib::GetPixel(int x, int y) const throw() {

View file

@ -32,7 +32,7 @@ public:
* @param None
* @exceptions None
*/
CImageException() throw() : BaseException(_T("ImageException")) {}
CImageException() throw() : BaseException("ImageException") {}
/** Constructor with string description
* @param message - This should be a useful message for error tracking.
* @exceptions None

View file

@ -0,0 +1,47 @@
// stdafx.h : Includedatei für Standardsystem-Includedateien,
// oder häufig verwendete, projektspezifische Includedateien,
// die nur in unregelmäßigen Abständen geändert werden.
#pragma once
#ifndef VC_EXTRALEAN
#define VC_EXTRALEAN // Selten verwendete Teile der Windows-Header nicht einbinden
#endif
// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
#ifndef WINVER // Lassen Sie die Verwendung von Features spezifisch für Windows 95 und Windows NT 4 oder später zu.
#define WINVER 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#endif
#ifndef _WIN32_WINNT // Lassen Sie die Verwendung von Features spezifisch für Windows NT 4 oder später zu.
//#define _WIN32_WINNT 0x0400 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#define _WIN32_WINNT 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#endif
#ifndef _WIN32_WINDOWS // Lassen Sie die Verwendung von Features spezifisch für Windows 98 oder später zu.
#define _WIN32_WINDOWS 0x0410 // Ändern Sie den entsprechenden Wert, um auf mindestens Windows Me abzuzielen.
#endif
#ifndef _WIN32_IE // Lassen Sie die Verwendung von Features spezifisch für IE 4.0 oder später zu.
#define _WIN32_IE 0x0400 // Ändern Sie den entsprechenden Wert, um auf mindestens IE 5.0 abzuzielen.
#endif
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // einige CString-Konstruktoren sind explizit
// Deaktiviert das Ausblenden von einigen häufigen und oft ignorierten Warnungen
#define _AFX_ALL_WARNINGS
#include "memory.h"
#include <afxwin.h> // MFC-Kern- und -Standardkomponenten
#include <afxext.h> // MFC-Erweiterungen
#include <afxdisp.h> // MFC-Automatisierungsklassen
#include <afxdtctl.h> // MFC-Unterstützung für allgemeine Steuerelemente von Internet Explorer 4
#include <stdio.h>
#include <stdarg.h>
#ifndef _AFX_NO_AFXCMN_SUPPORT
#include <afxcmn.h> // MFC-Unterstützung für allgemeine Windows-Steuerelemente
#endif // _AFX_NO_AFXCMN_SUPPORT

View file

@ -1,36 +1,42 @@
#include "stdafx.h"
#include <string>
#include <vector>
#include "PrimImplikanten.h"
#include "PrimImplikant.h"
using namespace std;
/*
bool PrimImplikant::valueAt(uint pos) {
for (vector<uint>::iterator i = implikanten.begin(); i < implikanten.end(); ++i)
if (*i == pos)
return true;
PrimImplikant::PrimImplikant(int input)
{
implikant.push_back(input);
}
*/
PrimImplikant::PrimImplikant(string input)
{
vector<int> arr;
}
bool PrimImplikant::valueAt(int x) {
return false;
}
int PrimImplikant::parser(string input){ // Analyser
string text = new char [input.size()];
//string text2 = new char [input.size()];
text= input;
char yytext[]= "";
for( int i=0;i<input.size();i++){
if(isdigit(text[i]))
char c;
while(c!=EOF)
c=getc(fpi);
void PrimImplikant::parser(string input) { // Analyser
uint implikant = 0;
string text0 = "";
string text1 = "";
for (uint i = 0; i < input.size(); i++)
{
char c = input[i];
if (c == 'x' || c == 'X')
{
text0 = input;
text1 = input;
text0[i] = '0';
text1[i] = '1';
parser(text0);
parser(text1);
return;
}
if (c != '0' && c != '1')
{
printf("**** FATAL ERROR **** %s is not binary\n", input);
return;
}
implikant <<= 1; // *2
implikant += (uint)c - (uint)'0';
}
implikanten.push_back(implikant);
}

View file

@ -0,0 +1,48 @@
#ifndef PRIMIMPLIKANT
#define PRIMIMPLIKANT
#include <string>
#include <vector>
using namespace std;
class PrimImplikant
{
public:
string name;
uint id;
PrimImplikant(string input)
{
name = input;
parser(input);
}
PrimImplikant(uint input)
{
char nameC[sizeof(uint)*8+1];
_itoa_s(input, nameC, sizeof(uint)*8+1, 10);
name = nameC;
implikanten.push_back(input);
}
PrimImplikant(uint input1, uint input2)
{
char nameC[sizeof(uint)*8+1];
_itoa_s(input1, nameC, sizeof(uint)*8+1, 10);
name = nameC;
_itoa_s(input2, nameC, sizeof(uint)*8+1, 10);
name.append("|");
name.append(nameC);
implikanten.push_back(input1);
implikanten.push_back(input2);
}
bool PrimImplikant::valueAt(uint position);
void PrimImplikant::parser(string input);
private:
vector<uint> implikanten;
};
#endif

View file

@ -0,0 +1,89 @@
//#include <iostream>
#include "stdafx.h"
#include <string>
#include <vector>
#include "PrimImplikantCollection.h"
using namespace std;
void PrimImplikantCollection::add(PrimImplikant* &PI)
{
PIVector.push_back(PI);
}
void PrimImplikantCollection::add(string input)
{
PrimImplikant* PI = new PrimImplikant(input);
PI->id = this->size();
this->add(PI);
}
void PrimImplikantCollection::add(uint input)
{
PrimImplikant* PI = new PrimImplikant(input);
PI->id = this->size();
this->add(PI);
}
void PrimImplikantCollection::add(uint input1, uint input2)
{
PrimImplikant* PI = new PrimImplikant(input1, input2);
PI->id = this->size();
this->add(PI);
}
bool PrimImplikantCollection::valueAt(uint position)
{
for (vector<PrimImplikant*>::iterator i = PIVector.begin(); i < PIVector.end(); i++)
if ((*i)->valueAt(position))
return true;
return false;
}
PrimImplikantCollection PrimImplikantCollection::primImplikantenAt(uint position)
{
PrimImplikantCollection pic;
for (vector<PrimImplikant*>::iterator i = PIVector.begin(); i < PIVector.end(); i++)
if ((*i)->valueAt(position))
pic.add(*i);
return pic;
}
bool PrimImplikantCollection::contains(PrimImplikant* foreign)
{
for (vector<PrimImplikant*>::iterator i = PIVector.begin(); i < PIVector.end(); i++)
if ((*i)->id == foreign->id)
return true;
return false;
}
uint PrimImplikantCollection::size()
{
return this->PIVector.size();
}
PrimImplikant* PrimImplikantCollection::back()
{
return this->PIVector.back();
}
PrimImplikant* PrimImplikantCollection::front()
{
return this->PIVector.front();
}
PrimImplikant* PrimImplikantCollection::at(uint &index)
{
return this->PIVector.at(index);
}
PrimImplikant* PrimImplikantCollection::operator[](uint &index){
if (index < PIVector.size())
return this->PIVector.at(index);
return 0;
}
void PrimImplikantCollection::Dispose()
{
for (uint i = 0; i < this->size(); i++)
delete this->at(i);
}

View file

@ -1,24 +1,33 @@
#ifndef PRIMIMPLIKANTCOLLEC
#define PRIMIMPLIKANTCOLLEC
//#include <iostream>
#include <string>
#include <vector>
#include "PrimImplikanten.h"
#include "PrimImplikant.h"
using namespace std;
#ifndef PRIMIMPLIKANTCOLLEC
#define PRIMIMPLIKANTCOLLEC
class PrimImplikantCollection{
public:
void Add(PrimImplikant &pi);
//void Add(string input);
void Add(int input);
void add(PrimImplikant* &PI);
void add(string input);
void add(uint input);
void add(uint input1, uint input2);
bool ValueAt(int position);
bool valueAt(uint position);
PrimImplikantCollection primImplikantenAt(uint position);
bool contains(PrimImplikant* foreign);
PrimImplikant SolveNextHazard();
void Dispose();
uint size();
PrimImplikant* back();
PrimImplikant* front();
PrimImplikant* at(uint &index);
PrimImplikant* operator[](uint &index);
private:
vector<PrimImplikant> PIVector;
}
vector<PrimImplikant*> PIVector;
};
#endif

View file

@ -1,25 +0,0 @@
#ifndef PRIMIMPLIKANTEN
#define PRIMIMPLIKANTEN
#include <string>
#include <vector>
#include <map>
using namespace std;
class PrimImplikant
{
public:
PrimImplikant(string input);
//PrimImplikant(int input);
bool valueAt(int position);
private:
map<string,int> implikant;
}
#endif

View file

@ -0,0 +1,90 @@
#include "stdafx.h"
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include "Cell.h"
#include "PrimImplikant.h"
#include "Wertetabelle.h"
using namespace std;
extern uint dimension;
extern uint numElements;
extern bool KNF;
void Wertetabelle::Print()
{
printHeader();
for (uint i = 0; i < numElements; i++)
{
cout << "| "; // => |
cout << setfill(' ') << setw((uint)ceil(log10((float)numElements))) << i; // => 4
cout << " |"; // => |
this->printI(i); // => 0 1 0 0
cout << "| "; // => |
cout << ((*this->cells)[i]->value ^ KNF); // => 1
cout << " |"; // => |
this->printPrimImplikanten(i); // => 0 0x1 4
cout << endl; // ==> | 4 | 0 1 0 0 | 1 | 0 0x1 4
if (i > 0 && i % 15 == 0 && numElements - i > 5) // reprint header so you dont have to scroll
//cout << this->makeHeader() << endl;
printHeader();
}
cout << string(this->width, '-') << endl;
}
string Wertetabelle::makeHeader()
{
bool setPad = padding.size() == 0;
string row2 = "|" + string((uint)ceil(log10((float)numElements)) + 2, ' ') + "|";
for (vector<string>::iterator v = variables->begin(); v < variables->end(); v++)
{
row2 += " " + *v;
if (setPad)
padding.push_back((v->size()-1) / 2.0f);
}
row2 += " | y |";
this->width = row2.size();
row2 += " PrimImplikanten";
return row2;
}
void Wertetabelle::printHeader()
{
string row2 = this->makeHeader();
cout << string(this->width, '-') << endl; // repeat '-' several times => ---------------------
cout << row2 << endl; // print header row => | a bärchen c d | y | PrimtImpl.
cout << string(this->width, '-') << endl; // repeat '-' several times => ---------------------
}
void Wertetabelle::printI(uint i)
{
string row = " ";
for (int j = dimension - 1; j >= 0; j--) // Variablen rückwärts durchlaufen (s.u.)
{
char iAtJ = (i & 0x1) + '0'; // Maskierung (aktuelle Stelle j, die ausgegeben wird)
i >>= 1; // Schieben für nächstes Mal
// ' ' + Padding left (' ') + 1 | 0 + Padding right (' ') + row
row = string((uint)ceil(padding[j]) + 1, ' ') + iAtJ + string((uint)floor(padding[j]), ' ') + row;
}
cout << row;
}
void Wertetabelle::printPrimImplikanten(unsigned int i)
{
cout << ' ';
Cell* cell = cells->at(i);
for (unsigned int pi = 0; pi < cell->primImplikanten.size(); pi++) // for every PrimImplikant in Cell
cout << cell->primImplikanten[pi]->name << " ";
}

37
GDE_3_2008/Wertetabelle.h Normal file
View file

@ -0,0 +1,37 @@
#include "stdafx.h"
#include <vector>
#include <string>
#include <iostream>
#include "Cell.h"
#include "PrimImplikant.h"
#include "Cell.h"
using namespace std;
#ifndef WERTETABELLE
#define WERTETABELLE
class Wertetabelle
{
public:
void Print();
Wertetabelle(vector<Cell*>* cells, vector<string>* variables)
{
this->cells = cells;
this->variables = variables;
}
private:
string makeHeader();
void printHeader();
void printI(unsigned int i);
void printPrimImplikanten(unsigned int i);
vector<Cell*>* cells;
vector<string>* variables;
vector<float> padding;
uint width;
};
#endif

View file

@ -11,12 +11,12 @@
// Ändern Sie folgende Definitionen für Plattformen, die älter als die unten angegebenen sind.
// Unter MSDN finden Sie die neuesten Informationen über die entsprechenden Werte für die unterschiedlichen Plattformen.
#ifndef WINVER // Lassen Sie die Verwendung von Features spezifisch für Windows 95 und Windows NT 4 oder später zu.
#define WINVER 0x0400 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#define WINVER 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#endif
#ifndef _WIN32_WINNT // Lassen Sie die Verwendung von Features spezifisch für Windows NT 4 oder später zu.
//#define _WIN32_WINNT 0x0400 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#define _WIN32_WINNT 0x0500 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#define _WIN32_WINNT 0x0501 // Ändern Sie den entsprechenden Wert, um auf Windows 98 und mindestens Windows 2000 abzuzielen.
#endif
#ifndef _WIN32_WINDOWS // Lassen Sie die Verwendung von Features spezifisch für Windows 98 oder später zu.

View file

@ -8,6 +8,11 @@
#include <iostream>
#include <fstream>
#include "CParser.h"
#include "PrimImplikant.h"
#include "PrimImplikantCollection.h"
#include "Cell.h"
#include "Wertetabelle.h"
#ifndef _USE_OLD_OSTREAMS
using namespace std;
@ -120,34 +125,149 @@ void Restart()
void user_main()
{
int ww,hh;
set_windowpos(0,0,600,400);
while(1){ // Endlosschleife
get_windowsize(&ww,&hh);
set_drawarea(ww,hh); // Setzen des Zeichenbereiches
clrscr();
cout <<"Startvorschlag Tiefe:10\nNeigung links:15,Wachstum links:0.7\nNeigung rechts: 18,Wachstum rechts:0.8\n";
cout <<"Tiefe ( >1 ): ";
cin >> baum.Tiefe; // Die Tiefe einlesen.
//int ww,hh;
//set_windowpos(0,0,600,400);
//while(1){ // Endlosschleife
// get_windowsize(&ww,&hh);
// set_drawarea(ww,hh); // Setzen des Zeichenbereiches
// clrscr();
// cout <<"Startvorschlag Tiefe:10\nNeigung links:15,Wachstum links:0.7\nNeigung rechts: 18,Wachstum rechts:0.8\n";
// cout <<"Tiefe ( >1 ): ";
// cin >> baum.Tiefe; // Die Tiefe einlesen.
cout<<"Neigung nach links in Grad: "; // Die Neigung links einlesen.
cin >> baum.Neigung_links;
// cout<<"Neigung nach links in Grad: "; // Die Neigung links einlesen.
// cin >> baum.Neigung_links;
cout<<"Wachstum nach links ( <1 ): ";// Das Wachstum links einlesen...
cin >>baum.Wachstum_links;
// cout<<"Wachstum nach links ( <1 ): ";// Das Wachstum links einlesen...
// cin >>baum.Wachstum_links;
cout<<"Neigung nach rechts in Grad: ";
cin>>baum.Neigung_rechts;
// cout<<"Neigung nach rechts in Grad: ";
// cin>>baum.Neigung_rechts;
cout<<"Wachstum nach rechts ( <1 ): ";
cin>>baum.Wachstum_rechts;
// cout<<"Wachstum nach rechts ( <1 ): ";
// cin>>baum.Wachstum_rechts;
baum.WerteKorrigieren(); // Die Werte fuer das Wachstum ueberpruefen
// und wennn notwendig korrigieren.
Zeichne_Baum(); // Den Baum zeichnen.
cout << "Baum gezeichnet\n";
Restart(); // Den "Restart"-Button malen und auf eine Aktivierung warten.
if(StopProcess())break;
// baum.WerteKorrigieren(); // Die Werte fuer das Wachstum ueberpruefen
// // und wennn notwendig korrigieren.
// Zeichne_Baum(); // Den Baum zeichnen.
// cout << "Baum gezeichnet\n";
// Restart(); // Den "Restart"-Button malen und auf eine Aktivierung warten.
// if(StopProcess())break;
//
//}
FILE * input;
FILE * error;
FILE * list;
fopen_s(&input, "..\\res\\input.txt", "r");
if (input == 0)
{
cout << "Fehler Inputdatei";
system("pause");
return -1;
}
fopen_s(&error, "..\\res\\errorParser.txt", "a");
if (error == 0)
{
cout << "Fehler Fehlerdatei";
system("pause");
return -1;
}
fopen_s(&list, "..\\res\\listParser.txt", "w");
if (list == 0)
{
cout << "Fehler Listdatei";
system("pause");
return -1;
}
PrimImplikantCollection* globalPIC = new PrimImplikantCollection();
vector<string>* variables = new vector<string>();
CParser parser;
parser.IP_init_token_table();
parser.InitParse(input, error, list);
if (parser.yyparse(globalPIC, variables) != 0)
{
system("pause");
return 1;
}
system("pause");
/*pic.add(7);
pic.add("0x1");
pic.add("100");
pic.add("00x");
pic.add(4);
PrimImplikant prim7(7);
PrimImplikant prim13("0x1");
PrimImplikant prim4("100");
PrimImplikant prim4567("1xx");
pic.add(prim4567);*/
/*for (int p = 0; p < numElements; p++)
{
//printf("Pos %d: prim7=%d, prim13=%d, prim4=%d, prim4567=%d, pic=%d\n", p, prim7.valueAt(p), prim13.valueAt(p), prim4.valueAt(p), prim4567.valueAt(p), pic.valueAt(p));
printf("Pos %d: Matching collections: ", p);
PrimImplikantCollection matchingPIs = globalPIC->primImplikantenAt(p);
for (int i = 0; i < matchingPIs.size(); i++)
//cout << i->name < ", ";
printf("%s, ", matchingPIs[i]->name.c_str());
cout << endl;
}*/