Skip to content
Snippets Groups Projects
Commit 134d3464 authored by Van Herck, Walter's avatar Van Herck, Walter
Browse files

Added the basic classes for sample description and changed the UML slightly.

parent 87f747bd
No related branches found
No related tags found
No related merge requests found
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp \
nanoparticle.cpp \
layer.cpp \
homogeneousmaterial.cpp \
multilayer.cpp \
layerroughness.cpp \
exceptions.cpp
HEADERS += \
isample.h \
nanoparticle.h \
layer.h \
imaterial.h \
homogeneousmaterial.h \
multilayer.h \
layerroughness.h \
exceptions.h
#include "exceptions.h"
NotImplementedException::NotImplementedException(const std::string& message)
: std::logic_error(message)
{
}
NullPointerException::NullPointerException(const std::string& message)
: std::logic_error(message)
{
}
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#include <stdexcept>
class NotImplementedException : public std::logic_error
{
public:
NotImplementedException(const std::string& message);
};
class NullPointerException : public std::logic_error
{
public:
NullPointerException(const std::string& message);
};
#endif // EXCEPTIONS_H
#include "homogeneousmaterial.h"
HomogeneousMaterial::HomogeneousMaterial(double refractive_index)
: m_refractive_index(refractive_index)
{
}
#ifndef HOMOGENEOUSMATERIAL_H
#define HOMOGENEOUSMATERIAL_H
#include "imaterial.h"
class HomogeneousMaterial : public IMaterial
{
public:
HomogeneousMaterial(double refractive_index = 1);
virtual ~HomogeneousMaterial() {}
double getRefractiveIndex() { return m_refractive_index; }
private:
double m_refractive_index;
};
#endif // HOMOGENEOUSMATERIAL_H
#ifndef IMATERIAL_H
#define IMATERIAL_H
class IMaterial
{
public:
virtual ~IMaterial() {}
};
#endif // IMATERIAL_H
#ifndef ISAMPLE_H
#define ISAMPLE_H
#include "exceptions.h"
class ISample
{
public:
virtual ~ISample() {}
virtual void add(ISample* p_child);
// virtual void remove(ISample* p_child);
// virtual ISample* getChild(size_t index);
};
void ISample::add(ISample* p_child)
{
throw NotImplementedException("This sample class is not allowed to have subsamples.");
}
//void ISample::remove(ISample* p_child)
//{
// throw NotImplementedException("This sample class is not allowed to have subsamples.");
//}
//ISample *ISample::getChild(size_t index)
//{
// throw NotImplementedException("This sample class is not allowed to have subsamples.");
//}
#endif // ISAMPLE_H
#include "layer.h"
# include <stdexcept>
Layer::Layer()
{
}
Layer::~Layer()
{
}
void Layer::setThickness(double thickness)
{
if (thickness>=0.0)
{
m_thickness = thickness;
return;
}
throw new std::domain_error("Layer thickness cannot be negative");
}
#ifndef LAYER_H
#define LAYER_H
#include "isample.h"
#include "imaterial.h"
class Layer : public ISample
{
public:
Layer();
virtual ~Layer();
virtual void setThickness(double thickness);
virtual const double getThickness() const { return m_thickness; }
virtual void setBulkMaterial(IMaterial* p_material) { mp_bulk_material = p_material; }
virtual IMaterial* getBulkMaterial() { return mp_bulk_material; }
private:
IMaterial* mp_bulk_material;
double m_thickness;
// LayerRoughness* mp_top_roughness;
// LayerRoughness* mp_bottom_roughness;
};
#endif // LAYER_H
#include "layerroughness.h"
LayerRoughness *LayerRoughness::createSmoothLayerInterface(Layer *p_top_layer, Layer *p_bottom_layer)
{
}
#ifndef LAYERROUGHNESS_H
#define LAYERROUGHNESS_H
#include "layer.h"
class LayerRoughness
{
public:
static LayerRoughness* createSmoothLayerInterface(Layer* p_top_layer, Layer* p_bottom_layer);
protected:
LayerRoughness();
};
#endif // LAYERROUGHNESS_H
#include <iostream>
using namespace std;
int main()
{
cout << "Hello World!" << endl;
return 0;
}
#include <algorithm>
#include <stdexcept>
#include "multilayer.h"
MultiLayer::MultiLayer()
{
}
MultiLayer::~MultiLayer()
{
}
void MultiLayer::addLayerWithTopRoughness(Layer *p_layer, LayerRoughness *p_roughness)
{
if (!p_layer)
{
throw NullPointerException("The layer to add does not exist.");
}
if (getNumberOfLayers())
{
Layer* p_last_layer = dynamic_cast<Layer*>(m_layers[getNumberOfLayers()-1]);
LayerRoughness* p_top_roughness = p_roughness;
if (!p_top_roughness)
{
p_top_roughness = LayerRoughness::createSmoothLayerInterface(p_last_layer, p_layer);
}
m_layers.push_back(p_layer);
m_roughnesses.push_back(p_top_roughness);
return;
}
m_layers.push_back(p_layer);
}
void MultiLayer::add(ISample* p_child)
{
Layer* p_layer = dynamic_cast<Layer*>(p_child);
addLayerWithTopRoughness(p_layer, 0);
}
#ifndef MULTILAYER_H
#define MULTILAYER_H
#include <vector>
#include "layer.h"
#include "layerroughness.h"
class MultiLayer : public ISample
{
public:
MultiLayer();
~MultiLayer();
void addLayerWithTopRoughness(Layer* p_layer, LayerRoughness* p_roughness);
size_t getNumberOfLayers() { return m_layers.size(); }
// Overrides from ISample:
void add(ISample* p_child);
private:
std::vector<Layer*> m_layers;
std::vector<LayerRoughness*> m_roughnesses;
};
#endif // MULTILAYER_H
#include "nanoparticle.h"
NanoParticle::NanoParticle()
{
}
NanoParticle::~NanoParticle()
{
}
#ifndef NANOPARTICLE_H
#define NANOPARTICLE_H
#include "isample.h"
class NanoParticle : public ISample
{
public:
NanoParticle();
virtual ~NanoParticle();
};
#endif // NANOPARTICLE_H
This diff is collapsed.
...@@ -32,14 +32,18 @@ ...@@ -32,14 +32,18 @@
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_9S5eQXy_EeGw39HOdZIuIw" value="*"/> <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_9S5eQXy_EeGw39HOdZIuIw" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9S5eQny_EeGw39HOdZIuIw" value="1"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9S5eQny_EeGw39HOdZIuIw" value="1"/>
</ownedAttribute> </ownedAttribute>
<ownedAttribute xmi:id="_scxU8H2LEeGcxOnjc91t-Q" name="layerRoughness" type="_to-toHzAEeGw39HOdZIuIw" aggregation="composite" association="_scyjEH2LEeGcxOnjc91t-Q">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_scxU8X2LEeGcxOnjc91t-Q" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_scxU8n2LEeGcxOnjc91t-Q"/>
</ownedAttribute>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_sadhgHy_EeGw39HOdZIuIw" name="Layer"> <packagedElement xmi:type="uml:Class" xmi:id="_sadhgHy_EeGw39HOdZIuIw" name="Layer">
<generalization xmi:id="_wggJ0Hy_EeGw39HOdZIuIw" general="_XPLdEHyfEeGb2eulz0VMiA"/> <generalization xmi:id="_wggJ0Hy_EeGw39HOdZIuIw" general="_XPLdEHyfEeGb2eulz0VMiA"/>
<ownedAttribute xmi:id="_IlKAMHzBEeGw39HOdZIuIw" name="" type="_to-toHzAEeGw39HOdZIuIw" aggregation="shared" association="_IlKnQHzBEeGw39HOdZIuIw"> <ownedAttribute xmi:id="_IlKAMHzBEeGw39HOdZIuIw" name="" type="_sadhgHy_EeGw39HOdZIuIw" aggregation="shared" association="_IlKnQHzBEeGw39HOdZIuIw">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_IlKAMXzBEeGw39HOdZIuIw" value="2"/> <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_IlKAMXzBEeGw39HOdZIuIw" value="2"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_IlKAMnzBEeGw39HOdZIuIw" value="1"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_IlKAMnzBEeGw39HOdZIuIw" value="2"/>
</ownedAttribute> </ownedAttribute>
<ownedAttribute xmi:id="_b9TgoHzBEeGw39HOdZIuIw" name="material" type="_sX3EAHzAEeGw39HOdZIuIw" aggregation="shared" association="_b9UHsHzBEeGw39HOdZIuIw"> <ownedAttribute xmi:id="_b9TgoHzBEeGw39HOdZIuIw" name="material" type="_eMp6wH2KEeGcxOnjc91t-Q" aggregation="shared" association="_b9UHsHzBEeGw39HOdZIuIw">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_b9TgoXzBEeGw39HOdZIuIw" value="1"/> <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_b9TgoXzBEeGw39HOdZIuIw" value="1"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_b9TgonzBEeGw39HOdZIuIw" value="1"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_b9TgonzBEeGw39HOdZIuIw" value="1"/>
</ownedAttribute> </ownedAttribute>
...@@ -51,16 +55,22 @@ ...@@ -51,16 +55,22 @@
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9S7Tc3y_EeGw39HOdZIuIw" value="1"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_9S7Tc3y_EeGw39HOdZIuIw" value="1"/>
</ownedEnd> </ownedEnd>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_sX3EAHzAEeGw39HOdZIuIw" name="Material"> <packagedElement xmi:type="uml:Class" xmi:id="_sX3EAHzAEeGw39HOdZIuIw" name="IMaterial" isAbstract="true">
<ownedAttribute xmi:id="_OCSFUHzDEeGw39HOdZIuIw" name="m_name"> <ownedAttribute xmi:id="_OCSFUHzDEeGw39HOdZIuIw" name="m_name">
<type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/> <type xmi:type="uml:PrimitiveType" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#String"/>
</ownedAttribute> </ownedAttribute>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_to-toHzAEeGw39HOdZIuIw" name="LayerRoughness"/> <packagedElement xmi:type="uml:Class" xmi:id="_to-toHzAEeGw39HOdZIuIw" name="LayerRoughness">
<packagedElement xmi:type="uml:Association" xmi:id="_IlKnQHzBEeGw39HOdZIuIw" name="Top/bottom roughness" memberEnd="_IlKnQXzBEeGw39HOdZIuIw _IlKAMHzBEeGw39HOdZIuIw"> <ownedOperation xmi:id="_UpPOUH2LEeGcxOnjc91t-Q" name="createSmoothLayerInterface" isStatic="true">
<ownedEnd xmi:id="_IlKnQXzBEeGw39HOdZIuIw" name="" type="_sadhgHy_EeGw39HOdZIuIw" association="_IlKnQHzBEeGw39HOdZIuIw"> <ownedParameter xmi:id="_f4YAQH2LEeGcxOnjc91t-Q" name="top_layer" type="_sadhgHy_EeGw39HOdZIuIw"/>
<ownedParameter xmi:id="_iI3cMH2LEeGcxOnjc91t-Q" name="bottom_layer" type="_sadhgHy_EeGw39HOdZIuIw"/>
<ownedParameter xmi:id="_n2KWMH2LEeGcxOnjc91t-Q" name="smoothLayerInterface" type="_to-toHzAEeGw39HOdZIuIw" direction="return"/>
</ownedOperation>
</packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_IlKnQHzBEeGw39HOdZIuIw" name="Top/bottom layer" memberEnd="_IlKnQXzBEeGw39HOdZIuIw _IlKAMHzBEeGw39HOdZIuIw">
<ownedEnd xmi:id="_IlKnQXzBEeGw39HOdZIuIw" name="" type="_to-toHzAEeGw39HOdZIuIw" association="_IlKnQHzBEeGw39HOdZIuIw">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_IlKnQnzBEeGw39HOdZIuIw" value="2"/> <upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_IlKnQnzBEeGw39HOdZIuIw" value="2"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_IlKnQ3zBEeGw39HOdZIuIw" value="2"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_IlKnQ3zBEeGw39HOdZIuIw" value="1"/>
</ownedEnd> </ownedEnd>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_b9UHsHzBEeGw39HOdZIuIw" name="m_bulk_material" memberEnd="_b9UHsXzBEeGw39HOdZIuIw _b9TgoHzBEeGw39HOdZIuIw"> <packagedElement xmi:type="uml:Association" xmi:id="_b9UHsHzBEeGw39HOdZIuIw" name="m_bulk_material" memberEnd="_b9UHsXzBEeGw39HOdZIuIw _b9TgoHzBEeGw39HOdZIuIw">
...@@ -69,31 +79,18 @@ ...@@ -69,31 +79,18 @@
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_b9UHs3zBEeGw39HOdZIuIw"/> <lowerValue xmi:type="uml:LiteralInteger" xmi:id="_b9UHs3zBEeGw39HOdZIuIw"/>
</ownedEnd> </ownedEnd>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_pszWgHzBEeGw39HOdZIuIw" name="HomogeneousLayer">
<generalization xmi:id="_yvT40HzBEeGw39HOdZIuIw" general="_sadhgHy_EeGw39HOdZIuIw"/>
<ownedAttribute xmi:id="_acEh8HzCEeGw39HOdZIuIw" name="homogeneousMaterial" type="_vHBjgHzBEeGw39HOdZIuIw" association="_acFJAHzCEeGw39HOdZIuIw">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_acEh8XzCEeGw39HOdZIuIw" value="1"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_acEh8nzCEeGw39HOdZIuIw" value="1"/>
</ownedAttribute>
<ownedAttribute xmi:id="_dM4csHzCEeGw39HOdZIuIw" name="homogeneousMaterial" type="_vHBjgHzBEeGw39HOdZIuIw" aggregation="shared" association="_dM5DwnzCEeGw39HOdZIuIw">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_dM5DwHzCEeGw39HOdZIuIw" value="1"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_dM5DwXzCEeGw39HOdZIuIw" value="1"/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_vHBjgHzBEeGw39HOdZIuIw" name="HomogeneousMaterial"> <packagedElement xmi:type="uml:Class" xmi:id="_vHBjgHzBEeGw39HOdZIuIw" name="HomogeneousMaterial">
<generalization xmi:id="_yOx-oHzBEeGw39HOdZIuIw" general="_sX3EAHzAEeGw39HOdZIuIw"/> <generalization xmi:id="_yOx-oHzBEeGw39HOdZIuIw" general="_eMp6wH2KEeGcxOnjc91t-Q"/>
</packagedElement> <ownedOperation xmi:id="_qBmdkH2MEeGcxOnjc91t-Q" name="getRefractiveIndex">
<packagedElement xmi:type="uml:Association" xmi:id="_acFJAHzCEeGw39HOdZIuIw" name="homogeneousLayer_homogeneousMaterial_1" memberEnd="_acFJAXzCEeGw39HOdZIuIw _acEh8HzCEeGw39HOdZIuIw"> <ownedParameter xmi:id="_vWDZwH2MEeGcxOnjc91t-Q" name="refractive_index" type="_cHz1kHzDEeGw39HOdZIuIw" direction="return"/>
<ownedEnd xmi:id="_acFJAXzCEeGw39HOdZIuIw" name="homogeneousLayer" type="_pszWgHzBEeGw39HOdZIuIw" association="_acFJAHzCEeGw39HOdZIuIw"> </ownedOperation>
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_acFJAnzCEeGw39HOdZIuIw" value="1"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_acFJA3zCEeGw39HOdZIuIw" value="1"/>
</ownedEnd>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_dM5DwnzCEeGw39HOdZIuIw" name="m_bulk_material" memberEnd="_dM5Dw3zCEeGw39HOdZIuIw _dM4csHzCEeGw39HOdZIuIw"> <packagedElement xmi:type="uml:DataType" xmi:id="_cHz1kHzDEeGw39HOdZIuIw" name="double"/>
<ownedEnd xmi:id="_dM5Dw3zCEeGw39HOdZIuIw" name="homogeneousLayer" type="_pszWgHzBEeGw39HOdZIuIw" association="_dM5DwnzCEeGw39HOdZIuIw"> <packagedElement xmi:type="uml:Interface" xmi:id="_eMp6wH2KEeGcxOnjc91t-Q" name="IMaterial"/>
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_dM5DxHzCEeGw39HOdZIuIw" value="*"/> <packagedElement xmi:type="uml:Association" xmi:id="_scyjEH2LEeGcxOnjc91t-Q" name="m_roughnesses" memberEnd="_scyjEX2LEeGcxOnjc91t-Q _scxU8H2LEeGcxOnjc91t-Q">
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_dM5DxXzCEeGw39HOdZIuIw"/> <ownedEnd xmi:id="_scyjEX2LEeGcxOnjc91t-Q" name="multilayer" type="_fom_oHy_EeGw39HOdZIuIw" association="_scyjEH2LEeGcxOnjc91t-Q">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_scyjEn2LEeGcxOnjc91t-Q" value="1"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_scyjE32LEeGcxOnjc91t-Q" value="1"/>
</ownedEnd> </ownedEnd>
</packagedElement> </packagedElement>
<packagedElement xmi:type="uml:DataType" xmi:id="_cHz1kHzDEeGw39HOdZIuIw" name="double"/>
</uml:Model> </uml:Model>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment