jamescpp

oiascboafvboqae

Aug 18th, 2016
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.66 KB | None | 0 0
  1.  
  2. //complete syntax
  3. class example{
  4.  
  5.     T m_what_ever;
  6.  
  7.     T operator .read_only(){
  8.         return m_what_ever;
  9.     }
  10.  
  11.     T operator .any_use(const T& value){
  12.         m_what_ever = value;
  13.         return m_what_ever;
  14.     }
  15.  
  16.     void operator .write_only(const T& value){
  17.         m_what_ever = value;
  18.     }
  19.  
  20.     //default if both readonly and writeonly are defined
  21.     T operator .any_use_default(const T& value){
  22.         this.operator .any_use_default(const T& value); //call write only
  23.         return this.operator .any_use_default();        //call read only
  24.     }
  25. }
  26.  
  27. 1) READ ONLY VARIABLE
  28.     declaration:
  29.         class exampleReadOnly{
  30.             std::vector blabla;
  31.  
  32.             std::size_t operator .lenght(){
  33.                 return blabla.lenght();
  34.             }
  35.         }
  36.  
  37.     use:
  38.         exampleReadOnly container;
  39.         std::size_t len = container.lenght; //OK
  40.         container.lenght = 5;               //ERROR can't assign to readonly member | operator .lenght can't accept value ...
  41.  
  42.  
  43. 2) WRITE ONLY VARIABLE
  44.     this is not realy usefull but why not...
  45.  
  46.     declaration:
  47.         class authorizationClient{
  48.             std::string m_password;
  49.  
  50.             void operator .password(std::string value){
  51.                 m_password = value;
  52.             }
  53.         }
  54.  
  55.     use:
  56.         authorizationClient auth;
  57.         auth.password = "secret"; //OK
  58.         std::string stolenPassword = auth.password; //ERROR can't get value of writeonly member | void can't be converted to std::string ...
  59.  
  60.  
  61. 3) ANY ACCESS
  62.  
  63.     declaration
  64.         class user_databaseManaged{
  65.             uint id;
  66.             std::string m_sname;
  67.  
  68.             void operator .sname(std::string value){
  69.                 database.updateUserValue(id, "sname", value);    //void updateUserValue<T>(uint userId, std::string columnName, T value) throw (databaseError)
  70.                 m_sname = value;
  71.             }
  72.  
  73.             std::string operator .sname() {
  74.                 if(loadFromDbRequired){
  75.                     return database.getUserValue<std::string>(id, "sname"); //T getUserValue<T>(uint userId, std::string columnName) throw (databaseError, cantCastException)
  76.                 } else {
  77.                     return m_sname;
  78.                 }
  79.             }
  80.         }
  81.  
  82.     use:
  83.         user_databaseManaged currentUser(currentUserId);
  84.         std::string sname = currentUser.sname; //OK, database getUserValue called as side effect
  85.         currentUser.sname = "Jakub";           //OK, database setUserValue called as side effect
  86.         //loadFromDbRequired = false
  87.         std::string name = currentUser.sname    //OK, currentUser.m_sname returned
Advertisement
Add Comment
Please, Sign In to add comment