| 1 | /*!\file OptionLogical.cpp
|
|---|
| 2 | * \brief: implementation of the optionslogical object
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | /*Headers:*/
|
|---|
| 6 | /*{{{*/
|
|---|
| 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 <stdio.h>
|
|---|
| 14 | #include <string.h>
|
|---|
| 15 | #include "../objects.h"
|
|---|
| 16 | #include "../../../shared/shared.h"
|
|---|
| 17 | #include "../../../io/io.h"
|
|---|
| 18 | #include "../../../Container/Container.h"
|
|---|
| 19 | #include "../../../include/include.h"
|
|---|
| 20 | /*}}}*/
|
|---|
| 21 |
|
|---|
| 22 | /*Constructors/destructor/copy*/
|
|---|
| 23 | /*FUNCTION OptionLogical::OptionLogical(){{{*/
|
|---|
| 24 | OptionLogical::OptionLogical(){
|
|---|
| 25 |
|
|---|
| 26 | values =NULL;
|
|---|
| 27 |
|
|---|
| 28 | }
|
|---|
| 29 | /*}}}*/
|
|---|
| 30 | /*FUNCTION OptionLogical::~OptionLogical(){{{*/
|
|---|
| 31 | OptionLogical::~OptionLogical(){
|
|---|
| 32 |
|
|---|
| 33 | if (values) xDelete<bool>(values);
|
|---|
| 34 |
|
|---|
| 35 | }
|
|---|
| 36 | /*}}}*/
|
|---|
| 37 |
|
|---|
| 38 | /*Other*/
|
|---|
| 39 | /*FUNCTION OptionLogical::Echo {{{*/
|
|---|
| 40 | void OptionLogical::Echo(){
|
|---|
| 41 |
|
|---|
| 42 | char cstr[81];
|
|---|
| 43 | bool flag=true;
|
|---|
| 44 |
|
|---|
| 45 | if(flag) _pprintLine_("OptionLogical Echo:");
|
|---|
| 46 | Option::Echo();
|
|---|
| 47 |
|
|---|
| 48 | if (values && size) {
|
|---|
| 49 | if(numel == 1) if(flag) _pprintLine_(" values: " << (values[0] ? "true" : "false"));
|
|---|
| 50 | else{
|
|---|
| 51 | StringFromSize(cstr,size,ndims);
|
|---|
| 52 | if(flag) _pprintLine_(" values: " << cstr << " " << "logical");
|
|---|
| 53 | }
|
|---|
| 54 | }
|
|---|
| 55 | else if(flag) _pprintLine_(" values: [empty]");
|
|---|
| 56 | }
|
|---|
| 57 | /*}}}*/
|
|---|
| 58 | /*FUNCTION OptionLogical::DeepEcho() {{{*/
|
|---|
| 59 | void OptionLogical::DeepEcho(){
|
|---|
| 60 |
|
|---|
| 61 | char indent[81]="";
|
|---|
| 62 |
|
|---|
| 63 | OptionLogical::DeepEcho(indent);
|
|---|
| 64 |
|
|---|
| 65 | return;
|
|---|
| 66 | }
|
|---|
| 67 | /*}}}*/
|
|---|
| 68 | /*FUNCTION OptionLogical::DeepEcho(char* indent) {{{*/
|
|---|
| 69 | void OptionLogical::DeepEcho(char* indent){
|
|---|
| 70 |
|
|---|
| 71 | int i;
|
|---|
| 72 | int* dims;
|
|---|
| 73 | char indent2[81];
|
|---|
| 74 | char cstr[81];
|
|---|
| 75 | bool flag=true;
|
|---|
| 76 |
|
|---|
| 77 | if(flag) _pprintLine_(indent << "OptionLogical DeepEcho:");
|
|---|
| 78 | Option::DeepEcho(indent);
|
|---|
| 79 |
|
|---|
| 80 | xMemCpy<char>(indent2,indent,(strlen(indent)+1));
|
|---|
| 81 | strcat(indent2," ");
|
|---|
| 82 |
|
|---|
| 83 | if (values) {
|
|---|
| 84 | if(numel==1) if(flag) _pprintLine_(indent << " values: " << (values[0] ? "true" : "false"));
|
|---|
| 85 | else{
|
|---|
| 86 | dims=xNew<int>(ndims);
|
|---|
| 87 | for (i=0; i<numel; i++) {
|
|---|
| 88 | RowWiseDimsFromIndex(dims,i,size,ndims);
|
|---|
| 89 | StringFromDims(cstr,dims,ndims);
|
|---|
| 90 | if(flag) _pprintLine_(indent << " values" << cstr << ": " << (values[i] ? "true" : "false"));
|
|---|
| 91 | }
|
|---|
| 92 | xDelete<int>(dims);
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 | else if(flag) _pprintLine_(indent << " values: [empty]");
|
|---|
| 96 | }
|
|---|
| 97 | /*}}}*/
|
|---|
| 98 | /*FUNCTION OptionLogical::Name {{{*/
|
|---|
| 99 | char* OptionLogical::Name(){
|
|---|
| 100 |
|
|---|
| 101 | return(Option::Name());
|
|---|
| 102 | }
|
|---|
| 103 | /*}}}*/
|
|---|
| 104 | /*FUNCTION OptionLogical::NumEl {{{*/
|
|---|
| 105 | int OptionLogical::NumEl(){
|
|---|
| 106 |
|
|---|
| 107 | return(Option::NumEl());
|
|---|
| 108 | }
|
|---|
| 109 | /*}}}*/
|
|---|
| 110 | /*FUNCTION OptionLogical::NDims {{{*/
|
|---|
| 111 | int OptionLogical::NDims(){
|
|---|
| 112 |
|
|---|
| 113 | return(Option::NDims());
|
|---|
| 114 | }
|
|---|
| 115 | /*}}}*/
|
|---|
| 116 | /*FUNCTION OptionLogical::Size {{{*/
|
|---|
| 117 | int* OptionLogical::Size(){
|
|---|
| 118 |
|
|---|
| 119 | return(Option::Size());
|
|---|
| 120 | }
|
|---|
| 121 | /*}}}*/
|
|---|
| 122 | /*FUNCTION OptionLogical::Get(bool* pvalue) {{{*/
|
|---|
| 123 | void OptionLogical::Get(bool* pvalue){
|
|---|
| 124 |
|
|---|
| 125 | /*We should first check that the size is one*/
|
|---|
| 126 | if(this->NumEl()!=1){
|
|---|
| 127 | _error2_("option \"" << this->name << "\" has " << this->NumEl() << " elements and cannot return a single bool");
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | /*Assign output pointer*/
|
|---|
| 131 | *pvalue=this->values[0];
|
|---|
| 132 | }
|
|---|
| 133 | /*}}}*/
|
|---|