1 | // This file is a part of Framsticks GDK library. |
---|
2 | // Copyright (C) 2002-2006 Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.frams.alife.pl/ for further information. |
---|
4 | |
---|
5 | #ifndef _GENOTYPELOADER_H_ |
---|
6 | #define _GENOTYPELOADER_H_ |
---|
7 | |
---|
8 | #include "sstring.h" |
---|
9 | #include "multiparamload.h" |
---|
10 | |
---|
11 | /** Helper class, mostly useful with MultiParamLoader |
---|
12 | or its specialized version: MiniGenotypeLoader. |
---|
13 | MiniGenotype stores 3 essential fields of the Genotype (name, gene and info) |
---|
14 | */ |
---|
15 | class MiniGenotype |
---|
16 | { |
---|
17 | public: |
---|
18 | SString name,genotype,info; |
---|
19 | void clear() {name=""; genotype=""; info="";} |
---|
20 | }; |
---|
21 | |
---|
22 | |
---|
23 | /** Defines the association between "org:" object (found in genotype files) |
---|
24 | and the MiniGenotype fields. MiniGenotypeLoader uses this definition |
---|
25 | but you can also use it to make MultiParamLoader load genotype |
---|
26 | */ |
---|
27 | extern ParamEntry minigenotype_paramtab[]; |
---|
28 | |
---|
29 | |
---|
30 | /** In most simple cases this is the class you would use to load a series of genotypes from |
---|
31 | the Framsticks genotype file. |
---|
32 | |
---|
33 | Usage pattern: (see loadertest.cpp for the working code) |
---|
34 | |
---|
35 | 1.Initialize |
---|
36 | |
---|
37 | 2.while(genotype=loadNextGenotype()) doSomethingWith(genotype); |
---|
38 | |
---|
39 | 3.Done! |
---|
40 | |
---|
41 | MiniGenotypeLoader is simply the MultiParamLoader configured to load one kind of data: "org:" objects. |
---|
42 | The instance of this class can also be reconfigured to recognize more objects by using MultiParamLoader |
---|
43 | methods, or you can use it as a guide for creating your own specialized class. |
---|
44 | */ |
---|
45 | class MiniGenotypeLoader: public MultiParamLoader |
---|
46 | { |
---|
47 | MiniGenotype genotype_object; |
---|
48 | Param genotype_param; |
---|
49 | bool initialized; |
---|
50 | void init(); |
---|
51 | public: |
---|
52 | MiniGenotypeLoader(); |
---|
53 | MiniGenotypeLoader(VirtFILE *f); |
---|
54 | MiniGenotypeLoader(const char* filename); |
---|
55 | |
---|
56 | /** @returns genotype object if one was loaded or NULL otherwise. |
---|
57 | |
---|
58 | Returned MiniGenotype pointer always references the the same object (MiniGenotypeLoader::genotype_object) |
---|
59 | which means you may need to copy the data from it before calling loadNextGenotype() again. |
---|
60 | In the default configuration (simple MiniGenotypeLoader) NULL is always final and should be used |
---|
61 | to finish processing. |
---|
62 | |
---|
63 | If the loader is configured to load other objects or stop on other conditions, NULL will also mean |
---|
64 | every condition other than "GenotypeLoaded". In such cases you need MultiParamLoader::getStatus(), |
---|
65 | MultiParamLoader::finished() and other methods to determine the real cause of NULL. |
---|
66 | */ |
---|
67 | MiniGenotype* loadNextGenotype(); |
---|
68 | }; |
---|
69 | |
---|
70 | #endif |
---|