Bonchev Information Technologies and Systems
Software for organizations and people.
How to Use the Object Contextualization Model Hi guest
Sign up - Login
Object Contextualization Model Home How to Use Download License Text Awards & Reviews  
Object Contextualization Model Icon
To start using the Object Contextualization Model in a project, simply copy the supplied "Contextualize.h" header file in a folder on a path included in your project and #include "Contextualize.h" header file in the files where objects must be contextualized. Simple use of the Object Contextualization Model is shown in the code below.
#include <windows.h>
#include <stdio.h>
#include "..\Contextualize.h"


void fun1( bool boolIsApplication, bool boolIsDenominator )
{
   // Can easily make out of context assignments.
   boolIsApplication = boolIsDenominator;
   boolIsDenominator = boolIsApplication;
}


void fun2( contextualize< Bool, sX::Application > boolIsApplication, 
           contextualize< Bool, sX::Denominator > boolIsDenominator )
{
   // Cannot make out of context assignments.
   //boolIsApplication = boolIsDenominator;
   //boolIsDenominator = boolIsApplication;
}


class MyClass
{
public:
   bool fun_bool( bool bBoolean )
   {
      return( bBoolean ^ bBoolean );
   }

   bool fun_bool( contextualize< Bool, sX::Application > bBoolean )
   {
      return( bBoolean ^ bBoolean );
   }

   bool fun_bool( contextualize< Bool, sX::Denominator > bBoolean )
   {
      return( bBoolean ^ bBoolean );
   }

   bool operator==( const bool& bBoolean ) const
   {
      return( bBoolean );
   }

   bool operator==( const contextualize< Bool, sX::Application >& bBoolean ) const
   {
      return( bBoolean );
   }

   bool operator==( const contextualize< Bool, sX::Denominator >& bBoolean ) const
   {
      return( bBoolean );
   }
};


struct FileAttributes
{
   unsigned __int64 uiFileSize;
   DWORD dwAttributes;

   contextualize< FILETIME as sX::CreationTime   > ftCreationTime;
   contextualize< FILETIME as sX::LastAccessTime > ftLastAccessTime;
   contextualize< FILETIME as sX::LastWriteTime  > ftLastWriteTime;
};


void main()
{
   // ASSIGNMENT OPERATOR - The code below demonstrates how the Object Contextualization Model 
   // helps to eliminate incorrect assignment errors.


   // Create a Boolean variable contextualized with context of Application, e.g. as opposed to library.
   contextualize< Bool, sX::Application > boolIsApplication( contextualize< Bool, sX::Application >::Init( true ) );


   // Create a Boolean object contextualized with context of Denominator, e.g. as opposed to nominator.
   contextualize< Bool, sX::Denominator > boolIsDenominator( contextualize< Bool, sX::Denominator >::Init( false ) );


   // Notice that the selected contexts are chosen to be of an incompatible nature.


   // Bad assignment - variables from different contexts cannot be assigned except through explicit conversion.
   //boolIsApplication = boolIsDenominator;


   // Bad assignment - non contextualized data cannot be 
   // assigned to contextualized without an explicit conversion.
   //boolIsApplication = true;


   // OK assignment.
   boolIsApplication = contextualize< Bool, sX::Application >::Initialize( true );


   // Create a second Boolean contextualized as "Application".
   contextualize< Bool, sX::Application > boolIsApplication2( contextualize< Bool, sX::Application >::Init( false ) );


   // OK assignment – variables from the same type and context can be assigned immediately.
   boolIsApplication2 = boolIsApplication;


   // Invalid context assignment cannot be processed.
   // boolIsApplication = boolIsDenominator;


   // Example using data members.
   // Create two objects and initialize them with zeroes.
   FileAttributes faFileA = { 0 }, faFileB = { 0 };


   // ... some code to initialize the "faFileA" and "faFileB" objects.


   // OK call.
   faFileA.ftCreationTime = faFileB.ftCreationTime;


   // This line will generate an error.
   // faFileA.ftLastWriteTime = faFileB.ftLastAccessTime;


   // OK call.
   faFileA.ftLastWriteTime = contextualize< FILETIME as sX::LastWriteTime  >::Init( faFileB.ftLastAccessTime );


   // Context-specialize the object itself, which has contextualized members.
   contextualize< FileAttributes as contextualize< sX::Video by sX::Description > > faOfFileWithVideoDescription;


   //***************************************************************************************************
   // FUNCTION CALL - The code below demonstrates how the Object Contextualization Model 
   // helps to eliminate incorrect function call errors.


   // OK - this is a correct call.
   fun1( boolIsApplication, boolIsDenominator );


   // Bad call - the two variables are swapped by "mistake".
   // Because the function parameters are non-contextualized variables the compilation will not generate 
   // any errors. The discovery of the error is not assisted and will only happen by careful observation.
   fun1( boolIsDenominator, boolIsApplication );


   // OK - this is a correct call.
   fun2( boolIsApplication, boolIsDenominator );


   // Bad call - the two variables are swapped by "mistake".
   // Because the function parameters are contextualized the compiler will catch the 
   // error and not compile until the error is corrected or explicit conversion is made.
   //fun2( boolIsDenominator, boolIsApplication );


   // Bad call - non contextualized objects cannot be passed 
   // where contextualized are expected, except after explicit conversion.
   //fun2( true, false );


   // OK - this is a correct call.
   fun2( contextualize< Bool, sX::Application >::Init( true ), contextualize< Bool, sX::Denominator >::Init( false ) );


   //***************************************************************************************************
   // Operator - The code below demonstrates how the Object Contextualization Model 
   // enhances function and operator overloading.


   MyClass myClass;
   bool    b( false );


   // The respective overload function is called depending on the context of the supplied parameter.
   b = myClass.fun_bool( true );
   b = myClass.fun_bool( boolIsApplication );
   b = myClass.fun_bool( boolIsDenominator );


   // The respective operator overload is called depending on the context of the supplied parameter.
   b = myClass == true;
   b = myClass == boolIsApplication;
   b = myClass == boolIsDenominator;
}
Community Content
(To enter your comments you must be signed in. Log in or create FREE account.)
MemberComments
Be the first to comment.
Products
The ELIAS Project
Fine Art App
Information Presenter
Act On File
Audio Control
Photo Window
Information Presenter
Homepage
for Museums and Art galleries
for Schools and Universities
for Resorts, Hotels and Cruises
for Parks of any kind
for Corporations
for any business
Learning
Encryption and Authentication
Safe Online Communication
Website Testimonials
Learn how to store private keys
Make The Most From Your Files
Convenient Volume Control
Photo Window - an Awesome Gift
Support
My Account
FAQ - Forum
 
Community
Blog
Email this page
Newsletter
Bonchev IT
About
Contact
Download
Public Authentication Key
Public Encryption Key

Sitemap
Disclaimer
Privacy
Antispam
© Copyright 2024 Bonchev Information Technologies. All Rights Reserved.
Machine translation:
Search: 


Email this page
To:
use semicolon to separate emails eg: joe@abc.com; lea@abc.com
Subject:
Message:
a link to this page will be automatically added to your message
From:
Please type the anti-bot text below.
Type text:
Thank you for subscribing to the MBBSoftware newsletter.
Enter your email address:
Please type the anti-bot text below.
Type text: