For saving column order, I was thinking of using the CSettingsStore class to save and restore arrays of integers to and from the registry (arrays that I would use CListCtrl::GetColumnOrderArray() and CListCtrl::SetColumnOrderArray() to generate and set). But I have no idea if that's realistically possible, or what registry data type to use (DWORD? Stuff the ints into a string array and use multi-string?). Also, CSettingsStore requires a string path to open up keys, while GetAppRegistryKey() returns an HKEY, so I'm not sure how to even use CSettingsStore with my app.
I have 3 questions.
Will this approach be feasible for loading and saving of column information? Or is there an obviously simpler solution?
What data types should I use to store the column order arrays in the registry?
How can I convert an HKEY value to a CString? Or should I just look up my app's registry key and hardcode it?
My recommendation would be to format the column-count and the index values as a string delimited by comma (like 5, 1, 3, 4, 2, 0, the first number is column-count) and store it in the registry as REG_SZ with something like
AfxGetApp()->WriteProfileString(_T("Settings\\<ListControlName>"), _T("ColumnOrder"), sFormattedString);
You can load the string using GetProfileString() and use either CStringT::Tokenize() or the straight API strtok_s() functions to retrieve the values.
I used "Settings\\<ListControlName>" in case you need to store more values for each ListControl, like sort-order, for example. Otherwise, you could have just one registry section called "Settings\\ColumnOrder" and use <ListControlName> as the value-name.
Related
I'm storing a list of strings using Array datatype in Datastore(e.g. ["name1", "name2", ...]). As the list grows, I find myself unable to upsert the entry.
INVALID_ARGUMENT: Too many indexed properties
According to https://cloud.google.com/datastore/docs/concepts/entities#array, even if I set the property to be exclude_from_indexes, it gets ignored. The datastore web UI also doesn't have an Index checkmark for me to uncheck.
So the only option I came up with is to convert the Array into a String type and parse to a JSON Object every time I read from DB, and write back stringified.
Was wondering if this is the right approach or if there are better ways to do this I'm not aware of.
Thanks
You should set the exclude_from_indexes on each value of the array. That is what "For a property to be unindexed, the exclude_from_indexes field of Value must be set to true." means.
I'm trying to add an index to an attribute inside of a map object in DynamoDB and can't seem to find a way to do so. Is this something that is supported or are indexes really only allowed on scalar values? The documentation around this seems to be quite sparse. I'm hoping that the indexing functionality is similar to MongoDB but so far the approaches I've taken of referencing the attribute to index using dot syntax has not been successful. Any help or additional info that can be provided is appreciated.
Indexes can be built only on top-level JSON attributes. In addition, range keys must be scalar values in DynamoDB (one of String, Number, Binary, or Boolean).
From http://aws.amazon.com/dynamodb/faqs/:
Q: Is querying JSON data in DynamoDB any different?
No. You can create a Global Secondary Index or Local Secondary Index
on any top-level JSON element. For example, suppose you stored a JSON
document that contained the following information about a person:
First Name, Last Name, Zip Code, and a list of all of their friends.
First Name, Last Name and Zip code would be top-level JSON elements.
You could create an index to let you query based on First Name, Last
Name, or Zip Code. The list of friends is not a top-level element,
therefore you cannot index the list of friends. For more information
on Global Secondary Indexing and its query capabilities, see the
Secondary Indexes section in this FAQ.
Q: What data types can be indexed?
All scalar data types (Number, String, Binary, and Boolean) can be
used for the range key element of the local secondary index key. Set,
list, and map types cannot be indexed.
I have tried doing hash(str(object)) while I store the object separately. This hash gives me an integer(Number) and I am able to use a secondary index on it. Below is a sample in python, it is important to use a hash function which generates the same hash key every time for the value. So I am using sha1.
# Generate a small integer hash:
import hashlib
def hash_8_digits(source):
return int(hashlib.sha1(source.encode()).hexdigest(), 16) % (10 ** 8)
The idea is to keep the entire object small while still the entity intact. i.e. rather than serializing and storing the object as string and changing whole way the object is used I am storing a smaller hash value along with the actual list or map.
Maybe I am doing something wrong here. I am using a treeview control , which I populate with data. The data (integers mainly) are transformed to CStrings for that matter. When the user clicks on an item, I can read the CString, but then have to parse it in order to get the data .
Several times I have changed the way the data appears on the screen ,and then everything breaks, and I need to rewrite the parsing function. I wonder if there is a better way to do this...
EDIT : The treeview is being populated with items from a std::vector. If I could get the treeview to return an index in the vector instead of a CString , this would fit me perfectly.
You can use CTreeCtrl::SetItemData to associate an arbitrary data value with a tree item, and CTreeCtrl::GetItemData to retrieve this value. Typically you use SetItemData to store a pointer to an object, but in your case you could use this to store the integer values directly.
I hope this helps!
If you change the way you set/get your data in the tree, then you will have to change the way you format and and parse it.
Normally, you should only have 2 functions, the setter and the parser, so it should not be a big issue
I don't think there is a way to make it really faster or cleaner.
I am trying to get the IClass values from registry key using RegQueryVaueEx and convert them to GUID for my application. I could do that for REG_SZ size, however, I am trying to figure out a way to do the same for IClass values with REG_MULTI_SZ that have more than one IClass. It doesn't seem to be straightforward as characters between the values are not consistent. Sometimes, each value is delimited by a COMMA, sometimes the IClass value is equated to %b. Is there a simple way to achieve what I am looking for? Please suggest.
Looks like the best way to achieve this is to open the registry key of the driver with RegOpenKeyEx and use RegEnumValue to get the IClass values (by passing IClass value name as parameter) in a loop (do-while) until RegEnumValue fails.
Thanks all for the comments and suggestions.
Searching my WinXP/64 registry, I find no "IClass" value.
MSDN says that MULTI_SZ is a list of nul-terminated strings with a size value; and that page has example code that "walks a REG_MULTI_SZ string."
I'm relatively new to programming in C++ and I'm trying to create a data set that just has two values: an ID number and a string. There will be about 100,000 pairs of these. I'm just not sure what data structure would best suit my needs.
The data set has the following requirements:
-the ID number corresponding to a string is 6 digits (so 000000 to 999999)
-not all ID values between 000000 and 999999 will be used
-the user will not have permission to modify the data set
-I wish to search by ID or words in the String and return to the user ID and String
-speed of searching is important
So basically I'm wondering what I should be using (vector, list, array, SQL database, etc) to construct this data set and quickly search it?
the ID number corresponding to a string is 6 digits (so 000000 to
999999)
Good, use an int, or more precisely int32_t for the ID
-not all ID values between 000000 and 999999 will be used
Not a problem...
-the user will not have permission to modify the data set
Encapsulate your data within a class and you are good to go
-I wish to search by ID or words in the String and return to the user ID and String
Good, use Boost.Bimap
-speed of searching is important
I know, that's why you are using C++... :-)
You may also want to check SQLite : SQLite, can also function as an in-memory database.
use std::map
void main()
{
std::map<string /*id*/, string> m;
m["000000"] = "any string you want";
}
Vector & list are worst to use if you don't sort them, you don't want loop through all.
I suggest you use map, even tho building the entire map might take longer (nlogn). I still recommend it, since the runtime for searching is log(n) which is pretty fast!
"speed of searching is important"
I'd suggest something like a class which contains a vector of your id/string pairs, an unordered_map which maps id to an iterator or reference into that vector, and an unordered_map which maps a string to an iterator or reference into that vector. Then, two search functions in the class which look up the id/string pair based on the id or a string.
You have couple of options.
Use database, MySQL, SQLite etc. Performance depends on the database you use.
Or, if you want to do it in C++ code, you can use vectors. One vector for the key, another is for the string. You also need to map the related index between 2 vectors.
Sort both vectors after add a new item. Remember to update the map of related index
Then use binary search to find either key, or value. It shall be fast enough.