Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Inheritance.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/py/Inheritance.hh
11 /// @author Sergey Lyskov
12 ///
13 /// @note Defining various help classes to test C++ SubClassing in PyRosetta
14 
15 #ifndef INCLUDED_utility_py_Inheritance_hh
16 #define INCLUDED_utility_py_Inheritance_hh
17 
19 #include <utility/exit.hh>
20 
21 #include <string>
22 #include <iostream>
23 
24 namespace utility { namespace py {
25 
26 /** @details Dummy Value class to test if we can pass argument by-reference to PyRosetta sub-classes **/
27 class Value
28 {
29 public:
30  Value(std::string s="unknown") { s_=s; }
31  Value( Value const & src ) { std::cout << "Value Copy constructor! ["<< src.s_ << "]" << std::endl; utility_exit_with_message("Got Value copy-constructor call.. this really should not be happening... most likely is that PyRosetta sub-classing got broken!"); }
32 
33  ~Value() { std::cout << "Value destructor! ["<< s_ << "]" << std::endl; }
34 
35  std::string s() const { return s_; }
36  void s(std::string const & s) { s_=s; }
37 
38 private:
39  std::string s_;
40 };
41 
42 std::ostream & operator << ( std::ostream & os, Value const & v) { os << "Value('" << v.s() << "') "; return os; }
43 
44 typedef utility::pointer::shared_ptr< Value > ValueOP;
45 typedef utility::pointer::shared_ptr< Value const > ValueCOP;
46 
47 
48 /** @details Dummy Base class to test if inheritance work properly in PyRosetta **/
49 class Base
50 {
51 public:
52  Base() : int_value_(0) { std::cout << "Base::Base()" << std::endl; }
53 
55  std::string string_value_;
56 
57  virtual void foo_int(int i) { std::cout << "Base::foo_int( " << i << " )" << std::endl; }
58  virtual void foo_string(std::string s) { std::cout << "Base::foo_string( '" << s << "' )" << std::endl; }
59 
60  virtual void foo_value(Value& v ) { std::cout << "Base::foo_value( " << v << " )" << std::endl; }
61  virtual void foo_value_sp(ValueOP v) { std::cout << "Base::foo_value_sp( " << *v << " )" << std::endl; }
62 };
63 
64 typedef utility::pointer::shared_ptr< Base > BaseOP;
65 typedef utility::pointer::shared_ptr< Base const > BaseCOP;
66 
67 
68 void foo_all(Base &b, int i, Value &v, std::string s) { b.foo_int(i); b.foo_value(v); b.foo_string(s); }
69 void foo_all_sp(BaseOP b, int i, Value &v, std::string s) { b->foo_int(i); b->foo_value(v); b->foo_string(s); }
70 
71 
72 } } // namespace py namespace utility
73 
74 #endif // INCLUDED_utility_py_Inheritance_hh
#define utility_exit_with_message(m)
Exit with file + line + message.
Definition: exit.hh:47
Value(std::string s="unknown")
Definition: Inheritance.hh:30
virtual void foo_value_sp(ValueOP v)
Definition: Inheritance.hh:61
std::string s_
Definition: Inheritance.hh:39
Non-owning access smart pointer – dispatch class.
virtual void foo_value(Value &v)
Definition: Inheritance.hh:60
utility::pointer::shared_ptr< Base const > BaseCOP
Definition: Inheritance.hh:65
void foo_all(Base &b, int i, Value &v, std::string s)
Definition: Inheritance.hh:68
virtual void foo_int(int i)
Definition: Inheritance.hh:57
void s(std::string const &s)
Definition: Inheritance.hh:36
std::string s() const
Definition: Inheritance.hh:35
utility::pointer::shared_ptr< Base > BaseOP
Definition: Inheritance.hh:64
Program exit functions and macros.
virtual void foo_string(std::string s)
Definition: Inheritance.hh:58
std::ostream & operator<<(std::ostream &os, Value const &v)
Definition: Inheritance.hh:42
utility::pointer::shared_ptr< Value const > ValueCOP
Definition: Inheritance.hh:45
utility::pointer::shared_ptr< Value > ValueOP
Definition: Inheritance.hh:44
ocstream cout(std::cout)
Wrapper around std::cout.
Definition: ocstream.hh:287
void foo_all_sp(BaseOP b, int i, Value &v, std::string s)
Definition: Inheritance.hh:69
std::string string_value_
Definition: Inheritance.hh:55
Value(Value const &src)
Definition: Inheritance.hh:31