material_t
object
tar.gz
archive of your lab10/ directory, including:
README
file containing
Makefile
.h
headers and .cpp
source)
make clean
before tar
)
sendlab
notes
material_t
class in the material.h
interface, providing
the following class member functions:
// constructors (overloaded)
material_t();
// copy constructor
material_t(const material_t& rhs);
// destructor (default ok)
~material_t();
// assignment operator
const material_t& operator=(const material_t& rhs);
// friends (i/o)
friend std::ostream& operator<<(std::ostream& s, const material_t& rhs);
friend std::ostream& operator<<(std::ostream& s, material_t *rhs);
// methods
int getcookie();
std::string getname(;
drgb_t getamb();
drgb_t getdiff();
drgb_t getspec();
// private data members
private:
int cookie; // magic number
std::string name; // material name
drgb_t ambient; // ambient color
drgb_t diffuse; // ambient color
drgb_t specular; // ambient color
operator<<()
and operator>>()
must be implemented in the material_t
implementation material.cpp
main()
routine works unaltered:
int main()
{
list_t mats;
material_t *mat;
std::string entity,name;
// input should consist only of material definitions
// but there can be any number of material defs in the file
while(!std::cin.eof()) {
std::cin >> entity;
if(entity == "material" && std::cin.good()) {
std::cin >> (mat = new material_t());
std::cerr << mat->getname() << std::endl;
mats.add((void *)mat);
}
}
// read them all in...now try to print them
material_list_print(mats);
// see if we can find the first in the list, get its ambient data
if((mat = material_getbyname(mats,"blue")) != NULL) {
assert(mat->getcookie() == MAT_COOKIE);
std::cerr << "found " << mat->getname() << std::endl;
std::cerr << "ambient is: " << mat->getamb() << std::endl;
}
// see if we can find the last one, get its ambient data
if((mat = material_getbyname(mats,"yellow")) != NULL) {
assert(mat->getcookie() == MAT_COOKIE);
std::cerr << "found " << mat->getname() << std::endl;
std::cerr << "ambient is: " << mat->getamb() << std::endl;
}
// see what happens if we try to find a non-existent element
if((mat = material_getbyname(mats,"chartreuse")) != NULL) {
assert(mat->getcookie() == MAT_COOKIE);
std::cerr << "found " << mat->getname() << std::endl;
std::cerr << "ambient is: " << mat->getamb() << std::endl;
}
}
main.cpp
void material_list_print(list_t& mats);
material_t* material_getbyname(list_t& mats, std::string name);
material blue { ambient 0 0 5 diffuse 0 0 5 } material green { ambient 0 6 0 diffuse 0 7 0 specular 1 1 1 } material yellow { ambient 7 6 0 diffuse 7 7 0
blue green yellow material blue { ambient 0 0 5 diffuse 0 0 5 } material green { ambient 0 6 0 diffuse 0 7 0 specular 1 1 1 } material yellow { ambient 7 6 0 diffuse 7 7 0 } found blue ambient is: 0 0 5 found yellow ambient is: 7 6 0