Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 630177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:49:38+00:00 2026-05-13T19:49:38+00:00

I’m trying to do something like this, enum Data_Property { NAME, DATETIME, TYPE, };

  • 0

I’m trying to do something like this,

enum Data_Property
{
 NAME,
 DATETIME,
 TYPE,
};

struct Item_properties
{
  char* Name;
  char* DateTime;
  int Type;  
};

int main() {  
std::string data = "/Name Item_Name /DATETIME [TimeStamp] /TYPE [Integer value]";
std::list <std::string> known_properties;

known_properties.push_back("/Name");
known_properties.push_back("/DATETIME");
known_properties.push_back("/TYPE");

Item_properties item_p = extract_properties(data); //I use a function to get properties
                                                   //in a structure.

//here I want to use a switch-case statement to get the property by enum value
}

I need to know is there any way i can make it any simple? or how would i combine property keys like (/NAME /DATETIME /TYPE) with an enum and avoid using a std::list i.e known_properties?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T19:49:39+00:00Added an answer on May 13, 2026 at 7:49 pm

    First, let me say that there is always another alternative, one of my philosophies.

    Let’s look at the Big Picture. You are trying read an Item from string. The Item is a container of datums. In Object Oriented terms, the Item would like each datum to load its own data from a string. The Item doesn’t need to know how to load a datum, as it can request this from each datum.

    Your datums are actually more complex and intelligent than the C++ simple POD types. (Simple POD types don’t have field names.) So, you need to create classes to represent these (or to encapsulate the extra complexity). Trust me, this will be better in the long run.

    Here is a simple example of Refactoring the Name member:

    struct Name_Field
    {
      std::string  value;  // Change your habits to prefer std:string to char *
      void load_from(const std::string& text,
                     const std::string::size_type& starting_position = 0)
      {
         value.clear();
         std::string::size_type position = 0;
         position = text.find("/Name", starting_position);
         if (position != std::string::npos) // the field name was found.
         {
             // Skip the next space
             ++position;
    
             // Check for end of text
             if (position < text.length())
             {
                 std::string::size_t   end_position;
                 end_position = text.find_first_not_of(" ", position);
                 if (end_position != std::string::npos)
                 {
                     value = text.substr(position, end_position - position);
                 }
              }
          }
    };
    

    You can now add a load_from to the Item class:

    struct Item
    {
        Name_Field   Name;
        char *       DateTime;
        char *       Type;
        void load_from(const std::string& text)
        {
            std::string::size_t  position = 0;
    
            // Notice, the Name member is responsible for load its data,
            //    relieving Item class from knowing how to do it.
            Name.load_from(text, position);
        }
    };
    

    To load the item:

    Item new_item;
    new_item.load_from(data);
    

    As you refactor, be aware of common methods. For example, you may want to put common methods between Name_Field and DateTime_Field into a base (parent) class, Field_Base. This will simplify your code and design as well as support re-usability.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 365k
  • Answers 365k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can use the data in the /proc filesystem to… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer Do you still get the error when you use a… May 14, 2026 at 3:57 pm
  • Editorial Team
    Editorial Team added an answer You can use array_chunk to create a single array comprised… May 14, 2026 at 3:57 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.