API Decision
-
Hey there guys, I have an almost opinion question. I am writing an instant messenger software, and I am trying to decide on the internal API parsing method. I cannot decide if I want to have a one-size-fits-all method that parses the entire command then returns the specific section I need, or less simple-to-use library of functions that read individual functions. Basically, the command structure is like this: (Let's say you are registering a new connection) REG(##,{your username},{the password salted hash}) My first method would return the username when called as api_GETVALUE(2,"REG(33,username,passwordsalthash)"). If I changed the first argument to 1, it would return 33 (the length). If I did individual functions, I could get the length by calling api_GETLENGTH with the string as a parameter, api_GETUSERNAME for the username, etc. How would you guys do it personally? -- Collin
-
Hey there guys, I have an almost opinion question. I am writing an instant messenger software, and I am trying to decide on the internal API parsing method. I cannot decide if I want to have a one-size-fits-all method that parses the entire command then returns the specific section I need, or less simple-to-use library of functions that read individual functions. Basically, the command structure is like this: (Let's say you are registering a new connection) REG(##,{your username},{the password salted hash}) My first method would return the username when called as api_GETVALUE(2,"REG(33,username,passwordsalthash)"). If I changed the first argument to 1, it would return 33 (the length). If I did individual functions, I could get the length by calling api_GETLENGTH with the string as a parameter, api_GETUSERNAME for the username, etc. How would you guys do it personally? -- Collin
Your first option would have a problem in that you would have a single function that returns either a stirng (or maybe pointer to string) or an integer. But this is not legal in C++, as the compiler cannot distinguish (from return type alone) which one you mean. A better option would be to create a class (or structure) that holds the user information and has methods (getters) that return the relevant properties.