Pointwise Plugin SDK
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PwpAnchoredFileValue< ValType, ValWriter > Class Template Reference

Handles the delayed updating of a value in a PwpFile object. More...

#include <PwpAnchoredFileValue.h>

+ Collaboration diagram for PwpAnchoredFileValue< ValType, ValWriter >:

Public Member Functions

bool anchor (const char *suffix=0, const char *prefix=0, PWP_INT fldWidth=0)
 Anchors the value to the associated file's current file position and writes a placeholder value to the file. More...
 
bool anchor (PWP_INT fldWidth, const char *suffix=0, const char *prefix=0)
 Anchors the value to the associated file's current file position and writes a placeholder value to the file. More...
 
bool commit ()
 Writes the value to the associated file's anchored file position. More...
 
PwpFilef () const
 Gets the file associated with the anchored value. More...
 
PWP_INT fldWidth () const
 Gets the current value field width. More...
 
bool isAnchored () const
 Gets the current value anchoring status. More...
 
 operator const ValType & () const
 const ValType& cast operator. More...
 
 operator ValType & ()
 ValType& cast operator. More...
 
ValType & operator= (const ValType &rhs)
 ValType assignment operator. More...
 
const ValType & operator= (const ValType &rhs) const
 const ValType assignment operator. More...
 
const sysFILEPOSpos () const
 Gets the anchor position associated with the file. More...
 
const char * prefix () const
 Gets the current value prefix. More...
 
 PwpAnchoredFileValue (PwpFile &f)
 Constructor. More...
 
 PwpAnchoredFileValue (PwpFile &f, const ValType &initV, const char *suffix=0, const char *prefix=0, PWP_INT fldWidth=-1)
 Constructor. More...
 
 PwpAnchoredFileValue (PwpFile &f, const ValType &initV, PWP_INT fldWidth, const char *suffix=0, const char *prefix=0)
 Constructor. More...
 
bool rollback ()
 Moves the associated file to the anchored file position and unanchors the value. More...
 
const char * suffix () const
 Gets the current value suffix. More...
 
ValType & val ()
 Gets the current data value. More...
 
const ValType & val () const
 Gets the current data value. More...
 
 ~PwpAnchoredFileValue ()
 

Private Member Functions

PwpAnchoredFileValue< ValType, ValWriter > & operator= (const PwpAnchoredFileValue< ValType, ValWriter > &)
 
bool write ()
 

Private Attributes

bool anchored_
 
PwpFilef_
 
PWP_INT fldWidth_
 
sysFILEPOS pos_
 
const char * prefix_
 
const char * suffix_
 
ValType v_
 

Detailed Description

template<typename ValType, typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
class PwpAnchoredFileValue< ValType, ValWriter >

Handles the delayed updating of a value in a PwpFile object.

The PwpAnchoredFileValue template class implements the delayed updating of an anchored value in a PwpFile object. The file's format, precision, and byte-order are respected when the final value is committed.

Sometimes a value must be written to a file that is not know at the time it needs to be written out. Often, this value can be quickly computed by pre-processing the grid model. However, sometimes the pre-processing would be too time or memory intensive to perform on a large grid. In this case, a placeholder can be written to the file. Then, at some later stage of the export when the unknown value has been determined, the placeholder is updated with the correct value.

The ValType template parameter specifies the type of the data value written to the file.

The ValWriter template parameter specifies the type of the writer object that handles the interaction with the file.

Sample Usage:
#include "PwpFile.h"
void someFunction(PwpFile &file)
{
// Create the anchored value object (with value zero) using
// PwpAnchoredFileValueWriter as the writer. At this point, NO data is
// written to file and val is NOT yet anchored to a position in file.
PwpAnchoredFileValue<PWP_UINT32> val(file, 0, "\n", "val(", -10);
// Begin exporting data to file.
// ...
// ...
// At some point, you reach the part of the export where you need to
// write a value to the file that you do not yet know! Calling anchor()
// records file's current position and writes val to file as a
// placeholder.
val.anchor();
// Process the grid in a normal fashion and continue exporting data to
// the file. Along the way, compute val's correct value.
// ...
val = theActualValue; // calls operator=(const PWP_UINT32& v)
// ...
// We have reached the point where we know val's correct value! The
// call to commit() replaces the placeholder value in the file with the
// value currently stored in val. The file's format, precision, and
// byte-order are used when writing the value.
val.commit();
// Finish the export.
return true;
}
Template Parameters
ValTypeSpecifies the anchored value's data type.
ValWriterSpecifies the value writer type. It defaults to PwpAnchoredFileValueWriter<ValType>

Definition at line 169 of file PwpAnchoredFileValue.h.

Constructor & Destructor Documentation

◆ PwpAnchoredFileValue() [1/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::PwpAnchoredFileValue ( PwpFile f)
inline

Constructor.

Constructs an anchorable value for the specified file.

When the final value is committed to the file, the value will be written by the template ValWriter.

Parameters
fThe file containing the anchored value.

Definition at line 181 of file PwpAnchoredFileValue.h.

◆ PwpAnchoredFileValue() [2/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::PwpAnchoredFileValue ( PwpFile f,
const ValType &  initV,
const char *  suffix = 0,
const char *  prefix = 0,
PWP_INT  fldWidth = -1 
)
inline

Constructor.

Constructs an anchorable value for the specified file.

When the final value is committed to the file, the value will be written by the template ValWriter using the specified suffix, prefix, and fldWidth.

Parameters
fThe file containing the anchored value.
initVThe initial, placeholder value.
suffixThe value suffix used when writing to file.
prefixThe value prefix used when writing to file.
fldWidthThe value width used when writing to file.

Definition at line 206 of file PwpAnchoredFileValue.h.

◆ PwpAnchoredFileValue() [3/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::PwpAnchoredFileValue ( PwpFile f,
const ValType &  initV,
PWP_INT  fldWidth,
const char *  suffix = 0,
const char *  prefix = 0 
)
inline

Constructor.

Constructs an anchorable value for the specified file.

When the final value is committed to the file, the value will be written by the template ValWriter using the specified suffix, prefix, and fldWidth.

Parameters
fThe file containing the anchored value.
fldWidthThe value width used when writing to file.
initVThe initial, placeholder value.
suffixThe value suffix used when writing to file.
prefixThe value prefix used when writing to file.

Definition at line 233 of file PwpAnchoredFileValue.h.

◆ ~PwpAnchoredFileValue()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::~PwpAnchoredFileValue ( )
inline

Definition at line 245 of file PwpAnchoredFileValue.h.

Member Function Documentation

◆ anchor() [1/2]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::anchor ( const char *  suffix = 0,
const char *  prefix = 0,
PWP_INT  fldWidth = 0 
)
inline

Anchors the value to the associated file's current file position and writes a placeholder value to the file.

Parameters
suffixThe value suffix. If not specified, uses ctor value.
prefixThe value prefix. If not specified, uses ctor value.
fldWidthThe values width. If not specified, uses ctor value.
Returns
true on success.

Definition at line 258 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::anchored_, PwpAnchoredFileValue< ValType, ValWriter >::f_, PwpAnchoredFileValue< ValType, ValWriter >::fldWidth(), PwpAnchoredFileValue< ValType, ValWriter >::fldWidth_, PwpFile::getPos(), PwpAnchoredFileValue< ValType, ValWriter >::pos_, PwpAnchoredFileValue< ValType, ValWriter >::prefix(), PwpAnchoredFileValue< ValType, ValWriter >::prefix_, PwpAnchoredFileValue< ValType, ValWriter >::suffix(), PwpAnchoredFileValue< ValType, ValWriter >::suffix_, and PwpAnchoredFileValue< ValType, ValWriter >::write().

Referenced by PwpAnchoredFileValue< ValType, ValWriter >::anchor().

◆ anchor() [2/2]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::anchor ( PWP_INT  fldWidth,
const char *  suffix = 0,
const char *  prefix = 0 
)
inline

Anchors the value to the associated file's current file position and writes a placeholder value to the file.

Parameters
fldWidthThe values width.
suffixThe value suffix. If not specified, uses ctor value.
prefixThe value prefix. If not specified, uses ctor value.
Returns
true on success.

Definition at line 283 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::anchor(), PwpAnchoredFileValue< ValType, ValWriter >::fldWidth(), PwpAnchoredFileValue< ValType, ValWriter >::prefix(), and PwpAnchoredFileValue< ValType, ValWriter >::suffix().

◆ commit()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::commit ( )
inline

Writes the value to the associated file's anchored file position.

The current file position is restored after the value is updated.

Returns
true on success.

Definition at line 295 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::anchored_, PwpAnchoredFileValue< ValType, ValWriter >::f_, PwpFile::getPos(), PwpAnchoredFileValue< ValType, ValWriter >::pos_, PwpFile::setPos(), and PwpAnchoredFileValue< ValType, ValWriter >::write().

◆ f()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpFile& PwpAnchoredFileValue< ValType, ValWriter >::f ( ) const
inline

Gets the file associated with the anchored value.

Returns
The file by ref.

Definition at line 402 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::f_.

◆ fldWidth()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PWP_INT PwpAnchoredFileValue< ValType, ValWriter >::fldWidth ( ) const
inline

Gets the current value field width.

Returns
The value field width.

Definition at line 422 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::fldWidth_.

Referenced by PwpAnchoredFileValue< ValType, ValWriter >::anchor().

◆ isAnchored()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::isAnchored ( ) const
inline

Gets the current value anchoring status.

Returns
The true if the value is anchored.

Definition at line 432 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::anchored_.

◆ operator const ValType &()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::operator const ValType & ( ) const
inline

const ValType& cast operator.

Returns
The value by const ref.

Definition at line 340 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ operator ValType &()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue< ValType, ValWriter >::operator ValType & ( )
inline

ValType& cast operator.

Returns
The value by ref.

Definition at line 350 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ operator=() [1/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpAnchoredFileValue<ValType,ValWriter>& PwpAnchoredFileValue< ValType, ValWriter >::operator= ( const PwpAnchoredFileValue< ValType, ValWriter > &  )
inlineprivate

Definition at line 458 of file PwpAnchoredFileValue.h.

◆ operator=() [2/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
ValType& PwpAnchoredFileValue< ValType, ValWriter >::operator= ( const ValType &  rhs)
inline

ValType assignment operator.

Returns
The value by ref.

Definition at line 371 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ operator=() [3/3]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const ValType& PwpAnchoredFileValue< ValType, ValWriter >::operator= ( const ValType &  rhs) const
inline

const ValType assignment operator.

Returns
The value by const ref.

Definition at line 360 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ pos()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const sysFILEPOS& PwpAnchoredFileValue< ValType, ValWriter >::pos ( ) const
inline

Gets the anchor position associated with the file.

Returns
The file position by const ref.

Definition at line 412 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::pos_.

◆ prefix()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const char* PwpAnchoredFileValue< ValType, ValWriter >::prefix ( ) const
inline

Gets the current value prefix.

Returns
The value prefix.

Definition at line 382 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::prefix_.

Referenced by PwpAnchoredFileValue< ValType, ValWriter >::anchor().

◆ rollback()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::rollback ( )
inline

Moves the associated file to the anchored file position and unanchors the value.

The current value is NOT written to the file.

Returns
true on success.

Definition at line 308 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::anchored_, PwpAnchoredFileValue< ValType, ValWriter >::f_, PwpAnchoredFileValue< ValType, ValWriter >::pos_, and PwpFile::setPos().

◆ suffix()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const char* PwpAnchoredFileValue< ValType, ValWriter >::suffix ( ) const
inline

Gets the current value suffix.

Returns
The value suffix.

Definition at line 392 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::suffix_.

Referenced by PwpAnchoredFileValue< ValType, ValWriter >::anchor().

◆ val() [1/2]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
ValType& PwpAnchoredFileValue< ValType, ValWriter >::val ( )
inline

Gets the current data value.

Returns
The value by ref.

Definition at line 320 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ val() [2/2]

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const ValType& PwpAnchoredFileValue< ValType, ValWriter >::val ( ) const
inline

Gets the current data value.

Returns
The value by const ref.

Definition at line 330 of file PwpAnchoredFileValue.h.

References PwpAnchoredFileValue< ValType, ValWriter >::v_.

◆ write()

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::write ( )
inlineprivate

Member Data Documentation

◆ anchored_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
bool PwpAnchoredFileValue< ValType, ValWriter >::anchored_
private

◆ f_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PwpFile& PwpAnchoredFileValue< ValType, ValWriter >::f_
private

◆ fldWidth_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
PWP_INT PwpAnchoredFileValue< ValType, ValWriter >::fldWidth_
private

◆ pos_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
sysFILEPOS PwpAnchoredFileValue< ValType, ValWriter >::pos_
private

◆ prefix_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const char* PwpAnchoredFileValue< ValType, ValWriter >::prefix_
private

◆ suffix_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
const char* PwpAnchoredFileValue< ValType, ValWriter >::suffix_
private

◆ v_

template<typename ValType , typename ValWriter = PwpAnchoredFileValueWriter<ValType>>
ValType PwpAnchoredFileValue< ValType, ValWriter >::v_
private

The documentation for this class was generated from the following file:
PwpAnchoredFileValue::val
ValType & val()
Gets the current data value.
Definition: PwpAnchoredFileValue.h:320
PwpAnchoredFileValue.h
PwpAnchoredFileValue
Handles the delayed updating of a value in a PwpFile object.
Definition: PwpAnchoredFileValue.h:169
PwpFile
Writes solver files.
Definition: PwpFile.h:110
PwpFile.h