- A controlled access problem - 1 Update
- Here is my extended post about politics - 1 Update
- Modules - 1 Update
- This was my last post here - 1 Update
- You have to understand me more Sir and Madam - 1 Update
Vir Campestris <vir.campestris@invalid.invalid>: Dec 22 08:57PM I'm crawling through a codebase that's got use-after-free and leaks, among other interesting features. I'm trying to get smart pointers in - and they've helped. I've found several use-after-free, and the system reliability has gone up. But there's one area that's exercising my mind. It has a (family of) classes that represent data items. These are called Fields. They are associated with Nodes, and usually they are a member of a Node (again, there are several Node classes). When a Field is updated it makes a call to its parent Node to inform it that there is new data. So we have: class Field { Node * parent; Field(Node* parent): parent(parent) ... void update(...) { ... parent->notify() } class Node { ... Field foo; void notify(); } Just occasionally a Field is not a member datum of a Node, but it is constructed with a pointer to one. Which is where the fun starts - I'm not convinced the lifetime is correct. What I'd like to do is store a weak_ptr<Node> in the field. The trouble is that during Node construction there can be no shared_ptr, so there's no valid weak_ptr to store. In this case the constructor must take a raw Node* pointer. But I don't want any other code doing this, so I don't want Field(Node*) to be generally accessible. I do want it accessible to all the Node class constructors, including where it's a class derived from Node - so a simple friend won't work. I've ended up with this. But there must be a better way... Comments? What follows is a complete sample with two Node types and one Field. #include <iostream> #include <memory> class Password { // Only Datum can create this type. // Its content is nil, but its access is heavily restricted. friend class Datum; }; class Node; class Gatekeeper { // Only Node can call this method. Therefore only Node (via this) // and Datum (directly) can ever get hold of a Password. friend class Node; static constexpr Password const & get(); }; class Datum { // Only one of these fields will be filled in. // if mwParent is expired, and mpParent is null, // then that is an error. std::weak_ptr<Node> const mwParent; Node * const mpParent; // Allow Gatekeeper to see our Password. friend Gatekeeper; static constexpr Password const & password = Password(); public: // Restrictions on getting a Password mean only members // of this class and Node can call this. // Construct given a password and a shared_ptr to a Node. // This is used by make_shared. template <typename NodeDerived> Datum(Password const&, std::shared_ptr<NodeDerived> const & parent) : mwParent(parent), mpParent(nullptr) {} // Construct given a raw pointer to a Node. // This is used by Node to make its data objects. template <typename NodeDerived> Datum(Password const&, NodeDerived * parent) : mwParent(), mpParent(parent) {} template <typename NodeDerived> static std::shared_ptr<Datum> make_shared(std::shared_ptr<NodeDerived> const & parent) { return std::make_shared<Datum>(password, parent); } virtual void notify(); }; // Now we know Datum has a Password we can look at it. constexpr Password const & Gatekeeper::get() { return Datum::password; } class Node { Datum m1; protected: // Allow all Node-derived classes to have a Password. static constexpr Password const & password = Gatekeeper::get(); public: // Construct. Anyone can do this. // Set up our member datum with a pointer to us. Node(): m1(password, this) {} virtual void notify() { std::cerr << "Node::notify" << std::endl; }; void shout() { std::cerr << "Node::shout1"<< std::endl; m1.notify(); std::cerr << "Node::shout2"<< std::endl; } }; class Node2: public Node { Datum m2; public: // Construct. Anyone can do this. // Set up our member datum with a pointer to us. Node2(): m2(password, this) {} virtual void notify() { std::cerr << "Node2::notify" << std::endl; }; void shout() { std::cerr << "Node2::shout1"<< std::endl; Node::shout(); m2.notify(); std::cerr << "Node2::shout2"<< std::endl; } }; void Datum::notify() { if (mpParent) { std::cerr << "Datum::notify1" << std::endl; // The object we are inside must still exist mpParent->notify(); std::cerr << "Datum::notify2" << std::endl; } else { std::cerr << "Datum::notify3" << std::endl; // will crash if the "parent" has died mwParent.lock()->notify(); std::cerr << "Datum::notify4" << std::endl; } } int main() { { auto foo = std::make_shared<Node2>(); // Construct with a Datum that knows about a Node. // Anyone can do this, // but they must have a shared_ptr to the node. std::shared_ptr<Datum> bar = Datum::make_shared(foo); foo->shout(); bar->notify(); std::cerr << "All done" << std::endl; } } ... and since you've read this far - Merry Christmas / Saturnalia / etc. Andy |
Intelli2 <intelli2@mama.com>: Dec 22 08:42PM -0500 Hello..... I will post one time this kind of post on this C++ forum.. Here is my extended post about politics, read it all: Dears all i am here again to discuss politics.. Now what is the essence of politics ? The backbones of politics is being more sophistication that knows and that knows how to govern. So what is this being more sophistication ? You have to set the standard of morality. And we know that to be able to have a society , we have to enlarge our view of morality by taking into account individual morality and general morality, so we have to avoid the "bugs" of being too individualistic, so we have to know about morality and how to set morality. But what is morality, what is its essence ? Morality is a priori pure moral of the philosopher Kant inferred from reason and it is also empirical moral inferred from the empirical world, so morality must be more dynamic and it must adapt efficiently and correctly. And i am a more experienced in political philosophy to say that the backbones of a society is how to avoid chaos of being too individualistic and follow general morality correctly to be more efficient and correct, this is the weakness of nationalism , nationalism says also that it has to be nationalism , but this can be a bug because to be more prosperous or more rich we have to know how to respect others and how to invest into other countries and how to take advantage of the high growth of Africa or arab countries etc. and we have to know how to be confidence that higher the consumer confidence index , that means that other people that are not your people have to be confident in you to consume more products and services from you, so this is the a high priority, so we have to do politics taking into account all that, this is the weakness of nationalism, because nationalism of Israel today is not taking into account correctly those important criteria that we must take into account, because Israel must think bigger and include economy and business with arab countries into the equation of politics, Israel is not just religion of Jerusalem, Israel must evolve and nationalism around the world must evolve and stop to be childish that don't take into account the right variables and criteria. You have to know how to say i love you.. This is the main point in the game. I have talked about the essence of Diplomacy.. What do you think is Diplomacy ? You have to be wise to do Diplomacy, because you have to know how to say i love you and how to say i respect you so that to receive more, you have to convince the other by saying so.. Israel is now a shit eating country, because it doesn't know how to do Diplomacy with arab countries, and it doesn't know how to think bigger by thinking the after and the after after with arabs.. this is the weakness of Israel of today, and this weakness is inherent to nationalism, because Israel is thinking more nationalism and religious nationalism without knowing how to give to palestians so that to receive from arab countries.. i am thinking economy Sir and Madam, this is why Israel must adapt quickly and know how to be efficient quickly, and how to be efficient is not thinking Jerusalem the capital of Israel, because thinking the after and the after after is knowing how to give a decent part of Jerusalem to palestinian arabs so that to receive from arab countries, receiving what ? i mean Israel has to think bigger and think economy with arabs and economic investment in arab countries and think doing more business in arab countries and why not doing more interesting big projects with arab countries. My way of thinking politics.. You have to understand my way of thinking, i am a white arab, so please try to be smart and understand my following writing: I understand some of you who consider nationalism as being national security, but this is still archaism , because this way of thinking nationalism is lacking global security that needs to be the right requirements that is capable of global security ! that is my way of thinking, this is why i am not confident with Donald Trump that is more a nationalist, i understand the positive way of thinking Donald Trump, but i am still not confident with Donald Trump, because we need more than nationalism that is more capable than nationalism and that is capable of governing the world, i mean you have to be capable of governning the world, because you need also global security that is needed to secure our national security, you see ? this is why i am not in accordance with Donald Trump ! so you have to convince smartly nationalism and not to get into violence with nationalism, this is what i am doing, and i think you need also sensibility to be capable of governing our world, i mean the right sensibility that is in accordance also with global security that secure our national security, this is why you have seen talking as i was talking in this forum of soc.culture.usa, I am a man that is more like a wise man, it is genetical in me, and i am more a sensitive soul that knows how to be sensibility.. If you look for example at a patato, what do you feel in front of this patato ? if you are sensibility , you will feel misery in front of this patato, and this feeling will call you to be more organized throughout the world and you will start to think bigger and construct bigger and organize bigger, that means that sensibility is also security, and it is also beauty. And about beauty Beauty is beauty, but the beauty of your body must be thought with wisdom, if we start to love a beautiful body and hate a not beautiful body, that's inferiority, because a beautiful body do also symbolize sex, and sex do represent inferior animal instincts, so we have to look at it with wisdom, and i think that we must prefer to it "the beauty of the mind", and the beauty of the mind is also being more organized in your mind so that we can feel it as sophistication, because as i said the sens of dignity do cause sophistication that causes confidence and respect that is the backbones of the moral and social contract, and this is like love. The sens of dignity What do you think is the sens of dignity ? Look at violent people, they don't have a correct sens of dignity Look at inferior people that don't have a correct sens of dignity.. We have to be careful, and make the sens of dignity at a high level of importance, because it is related to the social and moral contract, because having a sens of dignity is also making ourselves more sophistication that knows more how to survive better and how to manage itself and the world, so the sens of dignity do cause a sophistication that is required for respect and confidence, and respect and confidence is good for the moral and social contract, this is why you have seen me talking about technical sophistication, and finally you have understood that respect is derived from the sens of dignity that makes itself sophistication because it is a sens of dignity. So don't be fools by giving to fools and fanatics that don't have a correct sens of dignity. Here is also what i said before: How to be more love ? You have to be smart, i don't look at love as only love as we know, because being respect is also like love, because to be respect between us we have to love something important in persons that we respect, and this something important i think it is a kind of sophistication ! because we have to be frank that humans don't like inferiority, so this sophistication must be a sophistication that means sophistication today, not just inferior sophistication that is not in accordance with modernism of today, so modernism of today forces us to define sophistication by such as being more technical sophistication, that means being like technocrats to be more efficient and to attract more confidence in us, this is why i am a more serious software developer that has sophisticated more and more myself in software programming, because this sophistication in software programming do permit me to be more organized and that permit me to think in a more organized and more efficient fashion, and this way of doing do attract our confidence, so being more technical like being a more serious software developer do attract respect and confidence. Hope you have undertood my spirit. Also i have said: How about protection ? Where can you ask for protection ? You have to shape the society and shape the dictatorship of laws.. That's an interesting avenue, this is why we have to be smart , and we have to be a sophisticated spirit that knows how to construct confidence, how do you think we can construct confidence between people nationally and between people internationally ? that's an important question ! if you respond by nationalism, i will respond that nationalism is not sufficient, so we have to evolve, as you have seen me evolving on this forum, but you have to be more capable at evolving towards a better condition, this is why the essence of organization comes to the rescue, the essence of organization must be defined, and i have tried to define it in front of your eyes, so all in all the goals have to be clear, and we have to agree on the goals that make us more confident, and among the goals is the essence of organization, that means that we have to know how to organize ourselves and how to organize nationally and how to organize internationally, and the requirement then is to be more sophistication, such us being more and more technical, technocrats are good in this regard, but "confidence" is also knowing that we are more correct decency and dignity in accordance with our modernism, so i don't think that we must be pessimistic, because modernism of today is equipped more correctly to respond to our needs of decency and dignity, but why decency and dignity ? because of the social and moral contract, without being more confidence with your social and moral contract, you risk desorder and chaos and destructive violence, so all in all we can finally understand by this that real politics is also knowing how to construct confidence in your moral and social contract. Thank you, Amine Moulay Ramdane. |
woodbrian77@gmail.com: Dec 22 08:21AM -0800 On Thursday, December 21, 2017 at 5:26:37 AM UTC-6, Thiago Adams wrote: > I give just a sample with SQLite to answer "Is that how others are approaching it?". > I consider the amalgamation approach, that is used by sqlite and others, a > good approach to compose and consume libraries. OK, thanks for your comments. They inspired me to do some consolidating of my smaller files into one file. I'm a long ways though, from having just one header and one .cc file. > With this approach we have two files that can be used in a portable way > in different platforms. > It's not clear for me if modules have the property of being portable. That's an interesting question, but I'm not sure how much it will matter in practice. Brian Ebenezer Enterprises http://webEbenezer.net |
Intelli2 <intelli2@mama.com>: Dec 21 07:46PM -0500 Hello, This was my last post here. I have just posted few post here, so i will let you talk C++. Thank you, Amine Moulay Ramdane. |
Intelli2 <intelli2@mama.com>: Dec 21 06:52PM -0500 Hello, You have to understand me more Sir and Madam, i am also an inventor, and i have invented many scalable algorithms and such, i am not here to make jokes, i am here to be sophisticated, this is why you have seen me evolving in a more sophisticated manner, this is why i am working with C++ and modern Object Pascal, what i want is to make C++ and modern Object Pascal better, this is why i have invented and implemented the the following: My Scalable FIFO queues for C++ here: https://sites.google.com/site/aminer68/scalable-fifo-queues-for-c And my C++ synchronization objects library here: https://sites.google.com/site/aminer68/c-synchronization-objects-library and my Scalable Parallel C++ Conjugate Gradient Linear System Solver Library here: https://sites.google.com/site/aminer68/scalable-parallel-c-conjugate-gradient-linear-system-solver-library And i have also just invented a new fully scalable algorithm of a Threadpool and i am implementing it , so stay tuned ! I have also invented my Parallel archiver that works with C++Builder here: https://sites.google.com/site/aminer68/parallel-archiver I have also invented my Parallel Compression Library that works with C++Builder here: https://sites.google.com/site/aminer68/parallel-compression-library So stay tuned i am always making C++ and modern Object Pascal compilers better, you can find all my projects here, please take a look at them because they are much more stable and fast: https://sites.google.com/site/aminer68/ Thank you, Amine Moulay Ramdane. |
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page. To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com. |
No comments:
Post a Comment