copy

Python ctypes: copying Structure's contents

橙三吉。 提交于 2020-01-01 04:46:15
问题 I want to mimic a piece of C code in Python with ctypes, the code is something like: typedef struct { int x; int y; } point; void copy_point(point *a, point *b) { *a = *b; } in ctypes it's not possible to do the following: from ctypes import * class Point(Structure): _fields_ = [("x", c_int),("y", c_int)] def copy_point(a, b): a.contents = b.contents p0 = pointer(Point()) p1 = pointer(Point()) copy_point(p0,p1) as the contents still is a Python ctypes Structure object, that is managed as a

How to copy_if from map to vector?

谁说胖子不能爱 提交于 2020-01-01 03:03:30
问题 I'd like to copy values that match a predicate (equal ints) from a map<string,int> to a vector<int> . This is what I tried: #include <map> #include <vector> #include <algorithm> int main() { std::vector< int > v; std::map< std::string, int > m; m[ "1" ] = 1; m[ "2" ] = 2; m[ "3" ] = 3; m[ "4" ] = 4; m[ "5" ] = 5; std::copy_if( m.begin(), m.end(), v.begin(), [] ( const std::pair< std::string,int > &it ) { return ( 0 == ( it.second % 2 ) ); } ); } The error message from g++ 4.6.1 is : error:

Writing a deep copy - copying pointer value

荒凉一梦 提交于 2019-12-31 22:09:13
问题 In writing a copy constructor for a class that holds a pointer to dynamically allocated memory, I have a question. How can I specify that I want the value of the pointer of the copied from object to be copied to the pointer of the copied to object. Obviously something like this doesn't work... *foo = *bar.foo; because, the bar object is being deleted (the purpose of copying the object in the first place), and this just has the copied to object's foo point to the same place. What is the

How to use Command-c/Command-v shortcut in Mac to copy/paste text?

 ̄綄美尐妖づ 提交于 2019-12-31 10:58:47
问题 I have a Java Swing application that i want to run on Mac OS X. I want to use the normal Mac copy/paste shortcuts to copy/paste text to a text field in my Java application. Ctrl + c & Ctrl + v does the trick but i want to use Command + c & Command + v instead. How can i do that? 回答1: If you're using a 3rd-party L&F implementation it probably doesn't support the Mac's native keyboard shortcuts. The following code should reinstate the Mac's keyboard shortcuts for JTextField s after setting the

unwanted object property changed when changing another object property c#

人走茶凉 提交于 2019-12-31 04:58:07
问题 from what i understand in other posts i know that my objects use same place in memory but how to separate these objects? i tried to use new but it didn't work or i didn't used it correctly. Note that i didnt paste setter and getter here. class Supermarket { List<Product> _products = new List<Product>{ }; List<Customer> _customers = new List<Customer>{ }; } class Customer { List<Product> _purchased= new List<Product>{ }; } class Product { string _id; string _name; DateTime _expireDate; int

SQLite Database Copy Appears Corrupted When Generated by Device and not Emulator

时光毁灭记忆、已成空白 提交于 2019-12-31 03:21:08
问题 First I want to say thanks to everyone that reads this. Stackoverflow is an amazing site and you guys help me out with answers everyday in the form of questions already submitted. You all rock! My problem: I'm working on a database app that I'd like to back up the database at certian points so I can save the data I've collected in database over time, during development. So to save the database to accessible memory I've followed this page: How can I pull databases off my android onto my

Copy TreeView Node

倾然丶 夕夏残阳落幕 提交于 2019-12-31 01:52:27
问题 I am trying to copy the selected treeview node to the clip board so I can paste it in notepad. Here is my code but it doesn't work. TreeNode selNode = (TreeNode)this.treeView1.SelectedNode; Clipboard.SetData("TreeNode", selNode); 回答1: Notepad doesn't know anything about the Winforms TreeNode class. Use Clipboard.SetText() instead: private void treeView1_KeyDown(object sender, KeyEventArgs e) { if (e.KeyData == (Keys.Control | Keys.C)) { if (treeView1.SelectedNode != null) { Clipboard.SetText

Sparse files are huge with io.Copy()

我与影子孤独终老i 提交于 2019-12-31 01:40:47
问题 I want to copy files from one place to another and the problem is I deal with a lot of sparse files. Is there any (easy) way of copying sparse files without becoming huge at the destination? My basic code: out, err := os.Create(bricks[0] + "/" + fileName) in, err := os.Open(event.Name) io.Copy(out, in) 回答1: Some background theory Note that io.Copy() pipes raw bytes – which is sort of understandable once you consider that it pipes data from an io.Reader to an io.Writer which provide Read([

How to test if a file is fully copied in .NET

扶醉桌前 提交于 2019-12-30 17:19:29
问题 I am monitoring a folder for new files and need to process them. The problem is that occasionally file opening fails, because system has not finished copying it. What is the correct way to test if the file is finished copying? Clarification: I don't have write permissions to the folder/files and cannot control the copying process (it's the user). 回答1: I think the only sure way to do this is by trying to open the file exclusively and catching a specific exception. I usually hate using

How to copy a div's content to clipboard without flash

余生长醉 提交于 2019-12-30 06:15:48
问题 That's it :) I have a div with the id #toCopy , and a button with the id #copy . What's the best way to copy #toCopy content to clipboard when pressing #copy ? 回答1: UPDATED ANSWER Javascript was restricted from using the clipboard, early on. but nowadays it supports copy/paste commands. See documentation of mozilla and caniuse.com. document.execCommand('paste') make sure that you support browsers that don't. https://developer.mozilla.org/en-US/docs/Web/API/Document/execCommand http://caniuse