C++ Returning enumerated type


 
Thread Tools Search this Thread
Top Forums Programming C++ Returning enumerated type
# 1  
Old 11-22-2012
C++ Returning enumerated type

I am trying to create a function to return me the verbosity level, so I can call it
as follows

Code:
String  s = "normal";
Verbosity  log_level;
log_level = get_log_level(s);

I started a version in the last function but I am having trouble getting it to work.

Code:
#ifndef __VERBOSE_HH__
#define __VERBOSE_HH__

#include "string.hh"
#include "common.hh"

///////////////////////////////////////////////////////////////////////////////

/// \brief
/// sets the verbosity level.
/// \enum Verbose List of valid verbosity levels.

enum  Verbosity {
    none   = 0,
    low    = 1,
    normal = 2,
    medium = 3,
    high   = 4,
    full   = 5,
    diag   = 6
};

///////////////////////////////////////////////////////////////////////////////

/// \brief Sets the verbosity level defined by the user.
/// \param s String specifying the verbosity level.
/// \param vbLevel
/// \return bool Returns true if verbosity level is valid.

bool  get_log_level(
  String&  s,
  Verbosity&  log_level
) {

  if (s == String("none")) {
    log_level = none;
    return (true);

  } else if (s == String("low")) {
    log_level = low;
    return (true);

  } else if (s == String("medium")) {
    log_level = medium;
    return (true);

  } else if (s == String("high")) {
    log_level = high;
    return (true);

  } else if (s == String("full")) {
    log_level = full;
    return (true);

  } else if (s == String("diag")) {
    log_level = diag;
    return (true);

  } else {
    return (false);

  }

}

///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////

Verbosity&  get_log_level(
  String&  s
) {

  if (s == String("none")) {
//    log_level = none;
    return (none);

  } else if (s == String("low")) {
//    log_level = low;
    return (low);

  } else if (s == String("medium")) {
//    log_level = medium;
    return (medium);

  } else if (s == String("high")) {
//    log_level = high;
    return (high);

  } else if (s == String("full")) {
//    log_level = full;
    return (full);

  } else if (s == String("diag")) {
//    log_level = diag;
    return (diag);

  } else {
    return (normal);

  }

}

#endif

# 2  
Old 11-22-2012
Change your function from returning a Verbosity& (i.e. a reference to a Verbosity) to returning a Verbosity.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. What is on Your Mind?

Returning to the forum

hey guys, Im back! I hadnt thought about yall in a long time. I was googling away this morning and found a solution I needed from unix.com. good to see yall are still here and going strong! Im working as a Bladelogic Automation Engineer and have been doing HP and BMC server automation... (0 Replies)
Discussion started by: Kelam_Magnus
0 Replies

2. Shell Programming and Scripting

Script returning 0

hello i write a script which calculate free space but he always is 0 thats wrong with my script? getFileSystemPerformanceData() { if ; then if grep -q "Ubuntu" /etc/issue ; then CMD="df -lP | grep -v "\/home" | grep -v "\/dev/mapper/VolGroup-lv_root"" elif grep... (5 Replies)
Discussion started by: donatas1234
5 Replies

3. Shell Programming and Scripting

Returning -ve value in a pattern

Dear Friends, I need your help once more. I want to write a simple select as follows select amount from books where sr=1234 However, if value of "Amount" is negative then it should print it as follows. "3000-" and not as "-3000" Can you help me in this? Waiting for reply Anu. (2 Replies)
Discussion started by: anushree.a
2 Replies

4. Shell Programming and Scripting

Bash enumerated types

I have a variable, vbLevel and want to assign it to one of several values which are "none", "low", "medium", "high". Then I want to do something like if ; then ... fi (9 Replies)
Discussion started by: kristinu
9 Replies

5. UNIX for Advanced & Expert Users

find -type d returning files as well as directories

Can anyone see why the following command returns all files and not just the directories as specified? find . -type d -exec ls -F {} \; Also tried find . -type d -name "*" -exec ls -F {} \; find . -type d -name "*" -exec ls -F '{}' \; -print Always returns all files :-\ OS is... (2 Replies)
Discussion started by: tuns99
2 Replies

6. Shell Programming and Scripting

Returning the name of function used

Hi All In my script, I can call on several functions. I have a logging function that is called by any of these functions. What I would like is some way of identifying which function I am using and pass this to the log function as some parameter. Is there some built in command or way of... (3 Replies)
Discussion started by: kingpin2502
3 Replies

7. UNIX for Dummies Questions & Answers

FTP not returning CR

Hi all, I have a mainframe file which i am ftping to unix box. even though i have three records in my mainframe file the file on unix is coming as a single record. Can you help me out. Thanks, Hari (3 Replies)
Discussion started by: harikiranr
3 Replies

8. Programming

array type has incomplete element type

Dear colleagues, One of my friend have a problem with c code. While compiling a c program it displays a message like "array type has incomplete element type". Any body can provide a solution for it. Jaganadh.G (1 Reply)
Discussion started by: jaganadh
1 Replies

9. Shell Programming and Scripting

String type to date type

Can one string type variable changed into the date type variable. (1 Reply)
Discussion started by: rinku
1 Replies
Login or Register to Ask a Question