Generic configuration file processing library and executable6151605Abstract A method of configuring software applications is provided. A configuration file processing library implements a configuration file processor. Applications are compiled utilizing the configuration file processing library to generate generic configuration file processing code for reading and manipulating data in a generic configuration file. When the file is executed, the application stantiates a configuration file processor applications programming interface through which the configuration file is read or manipulated by applications independent of the user's operating environment. Claims What is claimed is: Description FIELD OF THE INVENTION
TABLE 1
______________________________________
# SAMPLE.CFG
# This section is a file comment. Each line begins with a pound sign,
# which identifies the line as a comment. Typically configuration
# files have some sort of header comment block such as this which
# explains the purpose and content of the file.
#
# For this configuration file the file comment might contain
# information identifying the application that owns this configuration
# file, the format of the file, why it is used, etc.
#
# Each line of this configuration file has the form:
# <attribute name>: <1st value>, <2nd value>, <3rd value>, <4th
# value>, <5th value>
#
# For this file the character ":" has been chosen to separate the
# <attribute name>from the <first value>, and the character ", " has
# been chosen to separate each of # the other values from each other.
#
# The interpretation of the content of the file is as follows:
# <Attribute Name> is the name of an individual.
# <1st value> is a street address.
# <2nd value> is a city.
# <3rd value> is a state.
# <4th value> is a zipcode.
# <5th value> is a phone number.
#
Bob Black: 100 Main St., Oakville, Colorado, 80888, 303-555-5555
Bill Brown: 200 Central, Elmville, Colorado, 80889, 303-555-6666
Ann Green: 300 1st St., Walnut City, Colorado, 80999, 303-555-7777
Sue White: 400 2nd Ave., Birchtown, Colorado, 88899, 303-555-8886
______________________________________
In Table 1, the defined layout for the data is, from left to right, the attribute name, colon, and then five values separated by commas. The name of the individual has five fields associated with it. A street address is mapped to the first value, a city to the second value, a state to the third value, a zipcode to the fourth value, and a telephone number to the fifth value. The current example is a database stored as a configuration file. As will be appreciated by those skilled in the art, the format of any given configuration file is arbitrary and can be defined using any syntax. A configuration file can include any number of primary keys followed by zero or more associated fields, comments, and field delimiting separator formats. To complicate matters further, each primary key may have a varying number of fields associated with it. Configuration file processing library 104 is a utility that allows an application 102 to work with any type of configuration file 100, having any number of fields per primary key, any number and position of comment fields, and any number and format of field delimiting separators. When an application 102 is compiled with configuration file processing library 104, the application is provided with the ability to easily create, manipulate, and or process configuration file 100 using object oriented processing methods. These methods allow the application to "get" and "set" attributes and associated values in the file. In the preferred embodiment, configuration processing library 104 also allows the application to "expand" strings by replacing tokens contained in an input string with the associated values from the configuration file 100. In accordance with a preferred embodiment of the invention, configuration file processing library 104 supports a "GetFirst" method, which returns data structures containing the values of the first attribute in the file to the application. Library 104 also supports a "GetNext" method, which when used with "GetFirst" method, allows the application developer to iterate through all entries in a configuration file, processing each as necessary. Library 104 also supports a getAttribute method which returns the appropriate list of values based on the attribute name specified. Library 104 also provides support for a "SetOrReplace" method, which allows the application developer to save attributes in the configuration file, overwriting an attribute with the same attribute name if one exists, or appending the new attribute to the end of the list if the attribute name specified is unique to the configuration file. Library 104 also supports an "ExpandString" method, which allows the application developer to specify a string as input which contains tokens that the developer wants replaced by the associated values from the configuration file. Because applications require varying configuration files, the configuration file processing library 104 of the invention supports unconstrained name space for the configuration filename, multi-byte character support for all aspects of the library 104, support for an unlimited number of primary keys, an unlimited number of fields per primary key, and a varying number of fields per primary key. Library 104 also supports the ability to define each of the separator characters used to parse each line in the configuration file into its primary key and associated fields, the ability to associate conceptual names, such as "street", "city", "state", "zipcode", "phone" with the fields for each attribute to enable easier human-readable processing of the data, and the ability to include end-of-line comments for each primary key. In accordance with the preferred embodiment of the invention, configuration file processing library 104 comprises a set of C++ classes which collectively provide generic configuration file processing capability. The primary class has one constructor of the form: ConfigFile<cfgFile>(<filename>,<sepChars>,<attrNames>,<Ignore EOL comments>) <cfgFile>is a variable name that assigns the class to an instantiation. Argument <filename>is a string that identifies the file path and file name of the configuration file to be processed. Argument <sepChars>is a white space delimited list of separator characters to recognize when parsing a line from the configuration file identified in <filename>into its associated "attribute name" and "values". The separator characters are processed in order from left to right, one separator character per parsed field. For example, if the string ": @" is specified as <sepChars>, then the primary key, or attribute name, will be anything preceding a first occurrence of a ":" character in the given line, and the "169 " character will be recognized as the separator used to parse the values for this attribute. The <sepchars>string can contain any number of characters. For example, if the string ": @.Salinity." is specified as <sepChars>, then the ":" would be recognized as separating the "attribute name" from the "first value", the "@" character would be recognized as separating the "first value" from the "second value", and the ".Salinity." character would be recognized as separating the "second value" from the "third value". The ".Salinity." character would also be recognized as separating the "3rd value" from the "4th value", the "fourth value" from the "fifth value", and so on, in the case where additional "#"characters existed in the line. As mentioned previously, separator characters are parsed from the <sepchars>string argument from left to right. If more separator characters than values exist in a given line, any unparsed separator characters contained in <sepchars>are ignored. If more values exist in a given line than separators specified in <sepChars>, the last separator character specified in the <sepchars>string is recognized as the separator character while parsing the remainder of the line. For example, a <sepchar>string having a value "," would be used to parse a standard comma delimited file, regardless of the number of fields associated with a given primary key of the file. The "," character would be recognized as separating all the fields for the primary key. A Null value specified in the <sepChars>parameter indicates that a default separator character (e.g.,",") is used to delimit fields in a line. Parameter <attrNames>maps conceptual names to fields of a primary key in the configuration file. This allows the configuration file data to be processed in human-readable form. By associating <attrNames>with fields, the application developer can then process the contents of the configuration file using those conceptual names. For example, to process sample configuration file SAMPLE.CFG, the <attrNames>string would be specified as "street city state zipcode telephone". This associates the conceptual identifiers "street", "city", "state", "zipcode", and "telephone" with their fields for each attribute name in configuration file SAMPLE.CFG. When more fields exist for a primary key than names specified by parameter <attrNames>, integers, presented as strings "1", "2", "3", ?, are used to identify the values. A Null value specified for <attrNames>parameter results in the default integer strings (i.e., "1", "2", "3", etc.) being used to identify the values for each primary key. Parameter <ignore EOL comments>is either true or false. If it is set to true, then the end-of-line comments in the configuration file (denoted in sample configuration file SAMPLE.CFG by beginning with "#") are completely ignored when the configuration file is parsed into primary keys and associated fields. If parameter <ignore EOL comments>is set to false, then the end-of-line comments are processed as part of the configuration file line. In this case, the <sepChar>string should have a "#" character as the last character so that the comments are parsed correctly. To utilize the configuration file processing utility of the invention, application 102 includes code to instantiate a configuration file processing object 300, as shown in FIG. 3, of the class ConfigFile using the constructor ConfigFile <cfgFile>(<filename>, <sepChars>, <attrNames>, <Ignore EOL comments>), and passing <filename>, <sepChars>, <attrNames>, and <Ignore EOL comments>parameters that are specific to the configuration file 100 that it is to interface with. Once configuration file processing object 300 is instantiated, the configuration file 100 specified by the <filename>parameter may be processed according to the specified <sepChars>, <attrNames>, and <Ignore EOL comments>parameters by performing method calls on one or more of methods getFileName, getFirstAttribute, getNextAttribute, getAttribute, setOrReplaceAttribute, and expandstring of configuration file processing object 300. In the preferred embodiment, results of this processing are stored in in-memory data structures for retrieval. The configuration file is kept synchronous to the in-memory data structures as changes are made to the in-memory data structures. The configuration file processing object 300 implements the following methods: getFileName, getFirstAttribute, getNextAttribute, getAttribute, setOrReplaceAttribute, and expandstring. Method getFileName returns a character string that contains the path to the configuration file or creates a file if it doesn't exist. In the preferred embodiment, the form of getFileName is: char * getFileName() Method getFirstAttribute returns the attribute name (i.e., primary key) and associated attribute values (i.e., associated fields) for the first data entry in the configuration file. The attribute name and associated values are determined at instantiation time, based on the <sepchars>passed into the constructor. In the preferred embodiment, the form of getFirstAttribute is: int getFirstAttribute(char *& name, AttributeList *& attrList) Method getNextAttribute returns the attribute name (i.e., primary key) and associated attribute values (i.e., fields) for the next data entry in the configuration file. The name and values are determined at instantiation time, based on the <sepchars>passed into the constructor. In the preferred embodiment, the form of getNextAttribute is: int getNextAttribute(char *& name, AttributeList *& attrList) If there are no more data entries in the configuration file, then the method returns a "-1", and <name>and <attrList>are set to NULL. Method getAttribute returns the appropriate list of values based on the attribute name specified. The name and values are determined at instantiation time, based on the <sepChars>parameter passed into the constructor. In the preferred embodiment, the form of getAttribute is: int getAttribute(const char *& name, AttributeList *& attrList) If there are no data entries in the configuration file matching the specified <name>, then the method returns a "-1" and <name>and <attrList>are set to NULL. Method setOrReplaceAttribute creates an entry in the specified configuration file based on the <name>and <attrList>parameters that are passed to it. The <sepchars>specified in the constructor are used to create the entry in the configuration file. In the preferred embodiment, the form of setOrReplaceAttribute is: int setOrReplaceAttribute(char * name, AttributeList * attrList) Method setOrReplaceAttribute returns a "o" (SUCCESS) unless a problem occurs in completing execution of the method call. Method expandstring uses the values stored in the configuration file to replace specific tokens in a string with the associated values from the configuration file. The token, which is recognized and replaced, is of the following form: ${<attribute name>:<attribute value>} Where <attribute name>is the desired attribute name from the configuration file, and <attribute value>identifies which value to retrieve. For example, given the sample configuration file located at "/config.fil" and the following instantiation: ConfigFile configFile("/config.file",":,","street city state zipcode telephone", 1); expandstring method could be invoked as follows: char * newStr =configFile.expandString("Bill Brown is from the city of ${Bill Brown:city}, in the state of ${Bill Brown:state}"); After execution of this method, newStr contains "Bill Brown is from the city of Elmville in the state of Colorado". A C++ code implementation is included in Appendix A. Although the invention has been described in terms of the illustrative embodiments, it will be appreciated by those skilled in the art that various changes and modifications may be made to the illustrative embodiments without departing from the spirit or scope of the invention. It is intended that the scope of the invention not be limited in any way to the illustrative embodiment shown and described but that the invention be limited only by the claims appended hereto.
|
Same subclass Same class Consider this |
||||||||||
