source: issm/trunk/src/c/Container/Options.cpp@ 13975

Last change on this file since 13975 was 13975, checked in by Mathieu Morlighem, 12 years ago

merged trunk-jpl and trunk for revision 13974

File size: 3.1 KB
Line 
1/*
2 * \file Options.c
3 * \brief: implementation of the Options class, derived from DataSet class
4 */
5
6/*Headers: {{{*/
7#ifdef HAVE_CONFIG_H
8 #include <config.h>
9#else
10#error "Cannot compile with HAVE_CONFIG_H symbol! run configure first!"
11#endif
12
13#include <vector>
14#include <algorithm>
15#include <cstring>
16
17#include "./DataSet.h"
18#include "../shared/shared.h"
19#include "../io/io.h"
20#include "../include/include.h"
21#include "../classes/classes.h"
22#include "../shared/shared.h"
23#include "../EnumDefinitions/EnumDefinitions.h"
24#include "../io/io.h"
25/*}}}*/
26
27/*Object constructors and destructor*/
28/*FUNCTION Options::Options(){{{*/
29Options::Options(){
30 return;
31}
32/*}}}*/
33/*FUNCTION Options::~Options(){{{*/
34Options::~Options(){
35 return;
36}
37/*}}}*/
38
39/*Object management*/
40/*FUNCTION Options::AddOption{{{*/
41int Options::AddOption(Option* in_option){
42
43 char* name=NULL;
44
45 vector<Object*>::iterator object;
46 Option* option=NULL;
47
48 /*In debugging mode, check that the option is not a NULL pointer*/
49 _assert_(in_option);
50
51 /*Also, check the option name*/
52 name=in_option->Name();
53
54 if(!name) _error_("input option has an empty name");
55 if(strchr(name,'.')) _error_("Option \"" << name << "\" has a protected character \".\"");
56 if(strchr(name,'[')) _error_("Option \"" << name << "\" has a protected character \"[\"");
57 if(strchr(name,']')) _error_("Option \"" << name << "\" has a protected character \"]\"");
58
59 /*Finally, check that no option of the same name already exists in the dataset*/
60 for(object=objects.begin();object<objects.end();object++){
61
62 option=dynamic_cast<Option*>(*object);
63 if (!strcmp(option->Name(),name)){
64 _error_("Options \"" << name << "\" found multiple times");
65 break;
66 }
67 }
68
69 /*OK, all checks went well, add option to dataset*/
70 this->AddObject(in_option);
71
72 return 1;
73}
74/*}}}*/
75/*FUNCTION Options::GetOption{{{*/
76Option* Options::GetOption(const char* name){
77
78 vector<Object*>::iterator object;
79 Option* option=NULL;
80
81 /*Go through options and find option: */
82 for ( object=objects.begin() ; object < objects.end(); object++ ){
83
84 option=dynamic_cast<Option*>(*object);
85 if (!strncmp(name,option->Name(),strlen(option->Name()))){
86
87 /*OK, now do we have a complete name? If not, it is a cell or a structure, we need to go further*/
88 if(!strcmp(name,option->Name())){
89 return option;
90 }
91 else{
92 /*If the object is a Cell, recursive call to its options*/
93 if(option->ObjectEnum()==OptionCellEnum){
94 GenericOption<Options*>* celloption=(GenericOption<Options*>*)option;
95 return celloption->value->GetOption(name);
96 }
97 /*If the object is a Struct loop over its size and recursive call*/
98 else if(option->ObjectEnum()==OptionStructEnum){
99 for(int i=0;i<option->NumEl();i++){
100 GenericOption<Options**>* structoption=(GenericOption<Options**>*)option;
101 _assert_(structoption->value[i]);
102 return structoption->value[i]->GetOption(name);
103 }
104 }
105 /*Else: not supported*/
106 else{
107 _error_("Cannot recover field \"" << name << "\" for an option of type " << EnumToStringx(option->ObjectEnum()));
108 }
109 }
110 }
111 }
112
113 /*Option not found return NULL pointer*/
114 return NULL;
115}
116/*}}}*/
Note: See TracBrowser for help on using the repository browser.